Why does typing a variable (or expression) print the value to stdout?Calling a function of a module by using...
Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?
Is there a non trivial covering of the Klein bottle by the Klein bottle
Reading Mishnayos without understanding
Co-worker sabotaging/undoing my work (software development)
How can I prevent an oracle who can see into the past from knowing everything that has happened?
Critique vs nitpicking
Can a player sacrifice a creature after declaring that creature as blocker while taking lethal damage?
Does it take energy to move something in a circle?
What does an unprocessed RAW file look like?
Coworker asking me to not bring cakes due to self control issue. What should I do?
Word for something that's always reliable, but never the best?
Taking an academic pseudonym?
What is an efficient way to digitize a family photo collection?
To be or not to be - Optional arguments inside definition of macro
Single-row INSERT...SELECT much slower than separate SELECT
Is there any danger of my neighbor having my wife's signature?
What to do with threats of blacklisting?
Crack the bank account's password!
The No-Straight Maze
How to not let the Identify spell spoil everything?
Renting a 2CV in France
Can me and my friend spend the summer in Canada (6 weeks) at 16 years old without an adult?
Equivalent of "illegal" for violating civil law
How long has this character been impersonating a Starfleet Officer?
Why does typing a variable (or expression) print the value to stdout?
Calling a function of a module by using its name (a string)How to return multiple values from a function?Convert bytes to a string?Emulate a do-while loop in Python?“Least Astonishment” and the Mutable Default ArgumentProper way to declare custom exceptions in modern Python?Python string formatting: % vs. .formatFastest way to check if a value exist in a listUsing IPython notebooks under version controlWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?
Take this example:
>>> 5+10
15
>>> a = 5 + 10
>>> a
15
How and why does Python do this without an explicit print statement?
If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way:
In[1]: 5+10
1
Out[1]: 1
Why does this happen?
python ipython read-eval-print-loop python-interactive
add a comment |
Take this example:
>>> 5+10
15
>>> a = 5 + 10
>>> a
15
How and why does Python do this without an explicit print statement?
If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way:
In[1]: 5+10
1
Out[1]: 1
Why does this happen?
python ipython read-eval-print-loop python-interactive
add a comment |
Take this example:
>>> 5+10
15
>>> a = 5 + 10
>>> a
15
How and why does Python do this without an explicit print statement?
If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way:
In[1]: 5+10
1
Out[1]: 1
Why does this happen?
python ipython read-eval-print-loop python-interactive
Take this example:
>>> 5+10
15
>>> a = 5 + 10
>>> a
15
How and why does Python do this without an explicit print statement?
If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way:
In[1]: 5+10
1
Out[1]: 1
Why does this happen?
python ipython read-eval-print-loop python-interactive
python ipython read-eval-print-loop python-interactive
edited 13 mins ago
Peter Mortensen
13.7k1986112
13.7k1986112
asked 8 hours ago
Chayan GhoshChayan Ghosh
1056
1056
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook
, originally specified in PEP 217.
If value is not None, this function prints it to sys.stdout, and saves it in builtin._.
sys.displayhook is called on the result of evaluating an expression entered in an interactive Python session.
You can modify this behavior:
>>> import sys
>>> def shook(expr):
... print(f'can haz {expr}?')
...
>>> sys.displayhook = shook
>>> 123
can haz 123?
>>> False
can haz False?
>>> None
can haz None?
And also set it back to normal:
>>> sys.displayhook = sys.__displayhook__
>>> 3
3
In the default Python repl, sys.displayhook
is
>>> import sys;
>>> sys.displayhook
<built-in function displayhook>
but in IPython it's
In [1]: import sys
In [2]: sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f630717fa58>
So that's why you see different behavior between Python and IPython.
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
add a comment |
That's how all interpreters work. They don't need any print
, but one thing, and without print
they do the repr
of everything, and print
doesn't, example:
>>> 'blah'
'blah'
>>> print('blah')
blah
>>>
Look at the quotes.
Also see this:
>>> print(repr('blah'))
'blah'
>>>
repr
does the same.
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54859437%2fwhy-does-typing-a-variable-or-expression-print-the-value-to-stdout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook
, originally specified in PEP 217.
If value is not None, this function prints it to sys.stdout, and saves it in builtin._.
sys.displayhook is called on the result of evaluating an expression entered in an interactive Python session.
You can modify this behavior:
>>> import sys
>>> def shook(expr):
... print(f'can haz {expr}?')
...
>>> sys.displayhook = shook
>>> 123
can haz 123?
>>> False
can haz False?
>>> None
can haz None?
And also set it back to normal:
>>> sys.displayhook = sys.__displayhook__
>>> 3
3
In the default Python repl, sys.displayhook
is
>>> import sys;
>>> sys.displayhook
<built-in function displayhook>
but in IPython it's
In [1]: import sys
In [2]: sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f630717fa58>
So that's why you see different behavior between Python and IPython.
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
add a comment |
When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook
, originally specified in PEP 217.
If value is not None, this function prints it to sys.stdout, and saves it in builtin._.
sys.displayhook is called on the result of evaluating an expression entered in an interactive Python session.
You can modify this behavior:
>>> import sys
>>> def shook(expr):
... print(f'can haz {expr}?')
...
>>> sys.displayhook = shook
>>> 123
can haz 123?
>>> False
can haz False?
>>> None
can haz None?
And also set it back to normal:
>>> sys.displayhook = sys.__displayhook__
>>> 3
3
In the default Python repl, sys.displayhook
is
>>> import sys;
>>> sys.displayhook
<built-in function displayhook>
but in IPython it's
In [1]: import sys
In [2]: sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f630717fa58>
So that's why you see different behavior between Python and IPython.
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
add a comment |
When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook
, originally specified in PEP 217.
If value is not None, this function prints it to sys.stdout, and saves it in builtin._.
sys.displayhook is called on the result of evaluating an expression entered in an interactive Python session.
You can modify this behavior:
>>> import sys
>>> def shook(expr):
... print(f'can haz {expr}?')
...
>>> sys.displayhook = shook
>>> 123
can haz 123?
>>> False
can haz False?
>>> None
can haz None?
And also set it back to normal:
>>> sys.displayhook = sys.__displayhook__
>>> 3
3
In the default Python repl, sys.displayhook
is
>>> import sys;
>>> sys.displayhook
<built-in function displayhook>
but in IPython it's
In [1]: import sys
In [2]: sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f630717fa58>
So that's why you see different behavior between Python and IPython.
When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook
, originally specified in PEP 217.
If value is not None, this function prints it to sys.stdout, and saves it in builtin._.
sys.displayhook is called on the result of evaluating an expression entered in an interactive Python session.
You can modify this behavior:
>>> import sys
>>> def shook(expr):
... print(f'can haz {expr}?')
...
>>> sys.displayhook = shook
>>> 123
can haz 123?
>>> False
can haz False?
>>> None
can haz None?
And also set it back to normal:
>>> sys.displayhook = sys.__displayhook__
>>> 3
3
In the default Python repl, sys.displayhook
is
>>> import sys;
>>> sys.displayhook
<built-in function displayhook>
but in IPython it's
In [1]: import sys
In [2]: sys.displayhook
Out[2]: <IPython.terminal.prompts.RichPromptDisplayHook at 0x7f630717fa58>
So that's why you see different behavior between Python and IPython.
edited 13 mins ago
Peter Mortensen
13.7k1986112
13.7k1986112
answered 8 hours ago
kojirokojiro
53.6k1387139
53.6k1387139
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
add a comment |
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
didn't know about the displayhook feature. Very helpful, thanks.
– Chayan Ghosh
8 hours ago
add a comment |
That's how all interpreters work. They don't need any print
, but one thing, and without print
they do the repr
of everything, and print
doesn't, example:
>>> 'blah'
'blah'
>>> print('blah')
blah
>>>
Look at the quotes.
Also see this:
>>> print(repr('blah'))
'blah'
>>>
repr
does the same.
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
add a comment |
That's how all interpreters work. They don't need any print
, but one thing, and without print
they do the repr
of everything, and print
doesn't, example:
>>> 'blah'
'blah'
>>> print('blah')
blah
>>>
Look at the quotes.
Also see this:
>>> print(repr('blah'))
'blah'
>>>
repr
does the same.
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
add a comment |
That's how all interpreters work. They don't need any print
, but one thing, and without print
they do the repr
of everything, and print
doesn't, example:
>>> 'blah'
'blah'
>>> print('blah')
blah
>>>
Look at the quotes.
Also see this:
>>> print(repr('blah'))
'blah'
>>>
repr
does the same.
That's how all interpreters work. They don't need any print
, but one thing, and without print
they do the repr
of everything, and print
doesn't, example:
>>> 'blah'
'blah'
>>> print('blah')
blah
>>>
Look at the quotes.
Also see this:
>>> print(repr('blah'))
'blah'
>>>
repr
does the same.
edited 11 mins ago
Peter Mortensen
13.7k1986112
13.7k1986112
answered 8 hours ago
U9-ForwardU9-Forward
15.7k51540
15.7k51540
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
add a comment |
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
any comment on the IPython behavior?
– Chayan Ghosh
8 hours ago
1
1
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
Let's say CPython in interactive mode works like that.
– Klaus D.
8 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54859437%2fwhy-does-typing-a-variable-or-expression-print-the-value-to-stdout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown