Input function in Python 3

2591

In this article, we will learn about

  • Python 3 builtin function: input()

You can simply use input() function for input data, the data entered using input is treated as a string.

Code: How to use the input function

print("Enter your age")
a=input()
print("Entered age is {}".format(a))
print("The type of value entered is {}".format(type(a)))

 

Output: 

Enter your age
34
Entered age is 34
The type of value entered is <class 'str'>

Explanation:

The type returned as a string in the output for the age data because input data is treated as a string.

 

You can also print message while input

Code: Print message while input

a = int(input("Enter your age: "))
print("Entered age is %d" % a)

 

Output: 

Enter your age: 345
Entered age is 345