brent thomas
brent thomas
Python Web Development Techdegree Student 13,402 Points

Does an input call prevent all following code from running until its received input?

Hey all, new to python and I'm currently taking the python basics course. In the "if, else, and elifs" video it has us request the users first name with the input() function. I noticed that if i insert random code after the input call, such as print("Hey man"), it won't run/print until the input has been received even though the two are irrelevant to each other . Is this normal? Am i right in assuming that any code after an input() call in a script won't run until the input has been received?

Thanks in advance

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 143,871 Points

Hi Brent. Welcome to Python.

You're right in thinking that the code essentially stops until input is received when executing the input() function call. This isn't unique to Python, but any language really. When you are asking for user input, the code stops until some input is received. The reason, generally, would be that if your asking for input, the code after is probably going to be doing something with that input, so the code is waiting for the input before proceeding.
When you say even your "random code" doesn't run, this is because code really is not smart. It doesn't know what the code is going to do until it does it. It doesn't know if the input is needed or not, so it just waits.

Hope that help to make sense.

:) :dizzy: