0

How the operators and commands in this code are executed?

Please explain, why the output to the screen in the second line is not executed, but waiting for input? print('what is your name?') print('Hi,', input())

3rd Sep 2025, 7:34 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
2 Respuestas
+ 3
The print function needs all of the argument values to be determined before they are passed into it. So the Python interpreter places 'Hi,' on the call stack, and then calls the input() function to get the next value to place on the call stack. After both arguments are determined, then it can call print(). EDIT: Note that the parentheses on the input() function make the distinction between whether the input function gets called first or gets passed as an argument. It passes the input function id without calling it if you pass it into print like this: print("Hi,", input) But then print won't call it either. It simply prints the meta description of the function.
3rd Sep 2025, 8:04 PM
Brian
Brian - avatar
+ 1
interesting. you can even reduce it to a one-liner: print('Hi,', input('what is your name?\n'))
3rd Sep 2025, 11:56 PM
Bob_Li
Bob_Li - avatar