Python input() is a built-in function that reads a line from input, converts it to a string (stripping a trailing newline), and returns that. Input can be from different sources but most often the input is from the keyboard.

python input() function

The flow of the program is stopped when input() function is called until the user has given the input ending with return key.

Python input() Syntax

input([prompt])

Python input() function takes only one parameter.

  • prompt (optional) – the string that is prompted to screen or written to any standard output.

input() does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation. For example, if EOF is read, it raises an EOFError exception.

Python input() Example

>>> input('Enter a String : ')
Enter a String : Python programming
'Python programming'

As you can see in above example, when we supply a string as the parameter to the input() function, an output is prompted to screen asking the user to give an input.

It keeps on taking input until the user enters the return key. In the example above, we entered ‘Python programming as input and hit the return key. Hence, it prints the input whatever we entered.