Skip to content

How to take integer array input in Python | Example code

  • by

It’s very easy to take array input in Python. Use input() function with map and split() functions.

Example take array input in Python

Simple example code.

If the numbers are provided in the same line then you can use them using a map().

arr = list(map(int, input().split()))



How to take integer array input in Python

If inputs are in different lines then, iterating till the range. Where enter N and then take N number of elements.

n = int(input('Enter how many Array elements: '))

arr = [int(input()) for i in range(n)]



Enter how many Array elements: 5
[1, 2, 3, 4, 5]

Do comment if you have any doubts or suggestions on this Python input topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.