Python Tutorial Python Advanced Python References Python Libraries

Python input() Function



The Python input() function is used to take input from user. It reads the line from input, and returns it.

Syntax

input(prompt)

Parameters

prompt Optional. Specify a string to represent as a default message before the input.

Example: using input() function

In the example below, the input() function is used to take input from user. The inputted value is 10 which is stored in variable num and printed using print() function.

num = input()
print("Inputted number is:", num )

The output of the above code will be:

10
Inputted number is: 10

Example: using input() function with a prompt

Here, input() function is used with prompt 'Enter any number: '. The prompt is printed while taking input from user as shown in the example.

num = input('Enter any number: ')
print("Inputted number is:", num )

The output of the above code will be:

Enter any number: 10
Inputted number is: 10

❮ Python Built-in Functions