What is the use of the input() function in Python?

The input() function takes data typed by the user from the keyboard. The program stops and waits until the user presses Enter, and then the value is returned as a string.

name = input("Enter your name: ")
print("Hello,", name)

age = int(input("Enter your age: "))
print("Next year you will be", age + 1)

Output:

Tutorials Class - Output Window

Enter your name: Robin
Hello, Robin
Enter your age: 20
Next year you will be 21

Remember that input() always gives a string, even if the user types a number. Use int() or float() to convert it before doing maths. Read more in the Python input() Function chapter.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.