why typing a variable (or expression) prints the value to stdout?Calling a function of a module by using its...

Where does documentation like business and software requirement spec docs fit in an agile project?

Coworker asking me to not bring cakes due to self control issue. What should I do?

Why is it that Bernie Sanders is always called a "socialist"?

Other than edits for international editions, did Harry Potter and the Philosopher's Stone receive errata?

Taking an academic pseudonym?

Does it take energy to move something in a circle?

Why are mages sometimes played bot instead of traditional ADCs?

What is a good reason for every spaceship to carry gun on board?

How long has this character been impersonating a Starfleet Officer?

How do you get out of your own psychology to write characters?

How to extract specific values/fields from the text file?

Crack the bank account's password!

Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?

How to deal with an underperforming subordinate?

How much light is too much?

The No-Straight Maze

Why did Luke use his left hand to shoot?

Possible issue with my W4 and tax return

What species should be used for storage of human minds?

Can me and my friend spend the summer in Canada (6 weeks) at 16 years old without an adult?

Is the percentage symbol a constant?

Create linguistic diagram (in TikZ?)

Equivalent of "illegal" for violating civil law

Does the US government have any planning in place to ensure there's no shortages of food, fuel, steel and other commodities?



why typing a variable (or expression) prints the value to stdout?


Calling a function of a module by using its name (a string)How to return multiple values from a function?“Least Astonishment” and the Mutable Default ArgumentPeak detection in a 2D arrayWhy is printing to stdout so slow? Can it be sped up?Redirect stdout to a file in Python?Speed comparison with Project Euler: C vs Python vs Erlang vs HaskellFastest way to check if a value exist in a listSuppress stdout / stderr print from Python functionsWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?













6















Take this example:



>>> 5+10
15
>>> a = 5 + 10
>>> a
15


My question is how and why python does 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?










share|improve this question



























    6















    Take this example:



    >>> 5+10
    15
    >>> a = 5 + 10
    >>> a
    15


    My question is how and why python does 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?










    share|improve this question

























      6












      6








      6








      Take this example:



      >>> 5+10
      15
      >>> a = 5 + 10
      >>> a
      15


      My question is how and why python does 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?










      share|improve this question














      Take this example:



      >>> 5+10
      15
      >>> a = 5 + 10
      >>> a
      15


      My question is how and why python does 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 printing stdout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 4 hours ago









      Chayan GhoshChayan Ghosh

      956




      956
























          2 Answers
          2






          active

          oldest

          votes


















          9














          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.






          share|improve this answer


























          • didn't know about the displayhook feature. Very helpful, thanks.

            – Chayan Ghosh
            4 hours ago



















          1














          That's how all interpreters work, they don't need any print, but one thing, without print does 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.






          share|improve this answer


























          • any comment on the IPython behavior?

            – Chayan Ghosh
            4 hours ago






          • 1





            Let's say CPython in interactive mode works like that.

            – Klaus D.
            4 hours ago











          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54859437%2fwhy-typing-a-variable-or-expression-prints-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









          9














          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.






          share|improve this answer


























          • didn't know about the displayhook feature. Very helpful, thanks.

            – Chayan Ghosh
            4 hours ago
















          9














          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.






          share|improve this answer


























          • didn't know about the displayhook feature. Very helpful, thanks.

            – Chayan Ghosh
            4 hours ago














          9












          9








          9







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 4 hours ago

























          answered 4 hours ago









          kojirokojiro

          53.5k1387138




          53.5k1387138













          • didn't know about the displayhook feature. Very helpful, thanks.

            – Chayan Ghosh
            4 hours ago



















          • didn't know about the displayhook feature. Very helpful, thanks.

            – Chayan Ghosh
            4 hours ago

















          didn't know about the displayhook feature. Very helpful, thanks.

          – Chayan Ghosh
          4 hours ago





          didn't know about the displayhook feature. Very helpful, thanks.

          – Chayan Ghosh
          4 hours ago













          1














          That's how all interpreters work, they don't need any print, but one thing, without print does 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.






          share|improve this answer


























          • any comment on the IPython behavior?

            – Chayan Ghosh
            4 hours ago






          • 1





            Let's say CPython in interactive mode works like that.

            – Klaus D.
            4 hours ago
















          1














          That's how all interpreters work, they don't need any print, but one thing, without print does 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.






          share|improve this answer


























          • any comment on the IPython behavior?

            – Chayan Ghosh
            4 hours ago






          • 1





            Let's say CPython in interactive mode works like that.

            – Klaus D.
            4 hours ago














          1












          1








          1







          That's how all interpreters work, they don't need any print, but one thing, without print does 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.






          share|improve this answer















          That's how all interpreters work, they don't need any print, but one thing, without print does 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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 4 hours ago

























          answered 4 hours ago









          U9-ForwardU9-Forward

          15.7k51540




          15.7k51540













          • any comment on the IPython behavior?

            – Chayan Ghosh
            4 hours ago






          • 1





            Let's say CPython in interactive mode works like that.

            – Klaus D.
            4 hours ago



















          • any comment on the IPython behavior?

            – Chayan Ghosh
            4 hours ago






          • 1





            Let's say CPython in interactive mode works like that.

            – Klaus D.
            4 hours ago

















          any comment on the IPython behavior?

          – Chayan Ghosh
          4 hours ago





          any comment on the IPython behavior?

          – Chayan Ghosh
          4 hours ago




          1




          1





          Let's say CPython in interactive mode works like that.

          – Klaus D.
          4 hours ago





          Let's say CPython in interactive mode works like that.

          – Klaus D.
          4 hours ago


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54859437%2fwhy-typing-a-variable-or-expression-prints-the-value-to-stdout%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

          Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

          How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...