User input in Python allows the program to gather information from a computer user. The program saves this input into a variable so that it can later be manipulated within the program.Continue Reading
A simple way to gather input in Python is using the "input" command. This command accepts free-response information from the keyboard, then saves the input in a format that matches the input. If the user types a string of text, the program saves the input as a string, whereas if the user types an integer, the program records this as an integer data type. When typing a string at an input prompt, the user must put the string inside of quotes; otherwise, Python interprets the input as a reference to a variable pre-allocated in the program. When no such variable exists, an error results and the program exits.
User inputs can also use more complex Python data types, including lists and dictionaries. However, the user must use the correct syntax for the data type to avoid errors. For a more permissive function to gather user input, consider the "raw_input" function.
The syntax for the "input" command follows the form Name = input("Type your name: "). In this syntax, "Name" is a variable created by the function to save the input. Inside the parentheses following input is the string of text displayed to the user to prompt the input. This is displayed to the user at the command prompt.Learn more about Computer Programming