Python input(): Getting User's Input
input() function is a part of the core library of standard Python distribution.
It reads the key strokes as a string object which can be referred to by a variable having a suitable name.
Note that the blinking cursor waits for the user's input. The user enters his input and then hits Enter. This will be captured as a string.
In the above example, the
input() function takes the user's input from the next line, e.g. 'Steve' in this case.
input() will capture it and assign it to a
name variable will display whatever the user has provided as the input.
input() function has an optional string parameter that acts as a prompt for the user.
input() function always reads the input as a string, even if comprises of digits. The type() function used earlier confirms this behaviour.
>>> name=input("Enter your name: ") Enter your name: Steve >>> type(name) <class 'str'> >>> age=input("Enter your age: ") Enter your age: 21 >>> type(age) <class 'str'>