Getting Input from User in Python
To receive information through the keyboard , Python uses the built-in function input() . This function has an optional parameter, commonly known as prompt , which is a string that will be printed on the screen whenever the function is called.
- prompt: A String, representing a default message before the input.
The input() function prompts text if a parameter is given. The functions reads input from the keyboard, converts it to a string and removes the newline (Enter). You should print some useful information to guide the user to enter the expected value.
New line for input() in Python
When you run this program, the python ask the data to enter the same line. If you want to receive data on next line , put a "\n" inside of the quotes.
"\n" is a control character, sort of like a key on the keyboard that you cannot press.
Python Integer as the User Input
To capture the input in your program, you will need a variable. A variable is a container to hold data. The input() function , by default, will convert all the information it receives into a string. So, there is no way to get an integer or any other type as the user input. However, we can use the built-in functions to convert the entered string to the integer.