Reading Time: 1 minutesGetting user input in Python
Getting user input in Python
The builtin input() is used for receiving input from the user. The input() function takes an argument, which is what will be prompted on the screen before the user enters a value. We can assign the value entered to a variable that we can use later in the program.
>>> input ( "Tell me your name. \n" ) |
>>> name = input ( "Tell me your name. \n" ) |
>>> print ( "Did you just say " + name + "?" ) |
Did you just say Tyrion Lannister? |
It is worth emphasizing that the input function returns a string, so if you require it to be some other data type, it needs to be converted into the required data type using Type Casting.
See also: