How to input array in Python

An array is a data structure that stores values of same type.
Method 1:
n = int(input("enter number of elements: ")) arr=[] for i in range(n): e=input() arr.append(e) print(arr)
Method 2
n = int(input("enter number of elements: ")) arr = list(map(int,input().strip().split()))[:n] print(arr)
Subscribe
Login
Please login to comment
0 Discussion