Open In App

How to take integer input in Python?

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this post, We will see how to take integer input in Python. As we know that Python's 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.

Let us see the examples:

Example 1:

Python
# take input from user
input_a = input()

# print data type
print(type(input_a))

# type cast into integer
input_a = int(input_a)

# print data type
print(type(input_a))

Output:

100
<class 'str'>
<class 'int'>

Example 2:

Python
# string input
input_a = input()

# print type
print(type(input_a))

# integer input
input_b = int(input())

# print type
print(type(input_b))

Output:

10
<class 'str'>
20
<class 'int'>

Example 3:

Python
# take multiple inputs in array
input_str_array = input().split()

print("array:", input_str_array)

# take multiple inputs in array
input_int_array = [int(x) for x in input().split()]

print("array:", input_int_array)

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]

Example 4:

Python
# Python program to take integer input  in Python

# input size of the list
n = int(input("Enter the size of list : "))
# store integers in a list using map, split and strip functions
lst = list(map(int, input(
    "Enter the integer elements of list(Space-Separated): ").strip().split()))[:n]
print('The list is:', lst)   # printing the list

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]

Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy