+ 1

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
4 ответов
+ 4
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
+ 2
interesting. you can even combine it into a one-liner: print('Hi,', input('what is your name?\n'))
3rd Sep 2025, 11:56 PM
Bob_Li
Bob_Li - avatar
0
Slt les gars
5th Sep 2025, 3:27 AM
Choppa
0
I will explain why I asked my question. In the process of studying the theory, it was said that commands are executed sequentially and line by line from top to bottom. Here, in the last line of code, the print command was executed, and the input command was also included, although logically it should have been before the print command. This caused me a slight 🤏 confusion. 🤭
6th Sep 2025, 5:39 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar