Why does returning in Interactive Python print to sys.stdout?

后端 未结 5 1497
挽巷
挽巷 2021-01-16 04:18

I ran into something different today. Consider this simple function:

def hi():
    return \'hi\'

If I call it in a Python shell,

         


        
5条回答
  •  渐次进展
    2021-01-16 04:45

    Most interactive shells use a REPL loop - read-eval-print.

    They read your input. They evaluate it. And they print the result.

    Non-function examples are (using the ipython shell):

    In [135]: 3+3
    Out[135]: 6    # result of a math operation
    
    In [136]: x=3    # no result from an assignment
    
    In [137]: x
    Out[137]: 3    # evaluate the variable, and print the result - its value
    

提交回复
热议问题