Note 2.10.1.
If you are typing Python code in interpreter you might want to add a new line using “\n” as shown above.
input
that gets input from the keyboard (in Python 2.0, this function was named raw_input
). When this function is called, the program stops and waits for the user to type something. When the user presses Return
or Enter
, the program resumes and input
returns what the user typed as a string.input
to be displayed to the user before pausing for input:int
using the int()
function:>>> prompt = 'What...is the airspeed velocity of an unladen swallow?\n'
>>> speed = input(prompt)
What...is the airspeed velocity of an unladen swallow?
What do you mean, an African or a European swallow?
>>> int(speed)
ValueError: invalid literal for int() with base 10:
str
method.