input

input is the opposite of print. We use it to get typed input from the user:

>>> number = input("Enter your favorite number: ")
Enter your favorite number: 666
>>> print(number)
666
>>> quest = input('What is your quest? ')
What is your quest? To seek the holy grail!
>>> print(quest)
To seek the holy grail!

After the user presses Enter, input will return whatever the user typed.

input might seem a little pointless right now. In the example above, you could have simply typed number = 666 instead of number = input("Enter your favorite number: "). The purpose of using input in this interactive mode is so you can learn how it works. In the next section, you will save a few commands in a file so that you can run them non-interactively. That’s when input becomes useful.


previous: variables next: batch mode