![]() |
VOOZH | about |
In Python, the built-in input() function always returns a string. To take integer input, the string must be typecast into an integer using the int() function. This article demonstrates multiple ways to take integer input in Python with examples.
Example 1: Taking Single Integer Input
Output
100
<class 'str'>
<class 'int'>
Explanation:
Example 2: Taking Multiple Inputs Separately
Output
10
<class 'str'>
20
<class 'int'>
Explanation:
Example 3: Taking Multiple Integer Inputs in a List
Output
10 20 30 40 50 60 70
array: ['10', '20', '30', '40', '50', '60', '70']
10 20 30 40 50 60 70
array: [10, 20, 30, 40, 50, 60, 70]
Explanation:
Example 4: Taking Integer Input with List Size
Output
Enter the size of list: 4
Enter the integer elements of list(Space-Separated): 6 3 9 10
The list is: [6, 3, 9, 10]