How to take integer input in Python 3

The inbuilt function input() in Python 3.x returns a str(string) class object. Irrespective of the input data type, it always returns a string.
In order to take integer input, we need to type cast those inputs into integers by using Python built-in int() function.
x = input() print(type(x)) print() y = int(input()) print(type(y))
Output:
22 <class 'str'> 22 <class 'int'>
Subscribe
Login
Please login to comment
0 Discussion