The input() function takes input from the user and returns it.
Syntax
input('prompt')input() Parameters
Python input() function parameters:
| Parameter | Condition | Description |
|---|---|---|
prompt |
Required | The text displayed before the user input |
input() Return
Python input() function returns the user's input in the form of a string.
Examples
Example 1: get string from user with input() function
For example, get input from user: s
inputString = input('Enter a string: ')
print('Input String: ', inputString)output
Enter a string: Python is here!
Input String: Python is here!Explanation:
- when the user runs the program, the prompt Enter a string: is displayed on the screen
- the user enters the input value
- the entered value is stored in inputString
- the program then prints the entered value using print
Example 2: get integer from user with input() function
Let's read a string from user and convert it to integer:
num = int(input("Enter a number: "))
print(f'The integer number is: {num}')output
Enter a number: 3
The integer number is: 3Example 3: get float from user with input() function
Let's read a string from the user and convert it to float:
float_num = float(input("Enter a floating number: "))
print(f'The floating number is: {float_num}')output
Enter a floating number: 12.3
The floating number is: 12.3