As we know that Python built-in input() function always returns a str(string) class object. So for taking integer input we have to type cast those inputs into integers by using Python built-in int() function.
How do you typecast in Python?
Explicit Type Casting
- Int() : Int() function take float or string as an argument and return int type object.
- float() : float() function take int or string as an argument and return float type object.
- str() : str() function take float or int as an argument and return string type object.
What is input () function in Python?
The input() function allows a user to insert a value into a program. input() returns a string value. You can convert the contents of an input using any data type. For instance, you can convert the value a user inserts to a floating-point number. input() is supported in Python 3.