+ 1

Python array

I need to use a a array with input, x=input() print(arr[x])

4th Dec 2019, 3:11 AM
Bruno
Bruno - avatar
2 Answers
+ 2
Thanks
4th Dec 2019, 3:25 PM
Bruno
Bruno - avatar
+ 1
You need an integral value for accessing a certain element in an array. So, assuming you already have an array <arr> you can do; x = int(input("Enter index of element: ")) if(x in range(len(arr))): print(arr[x]) else: print("Invalid index!")
4th Dec 2019, 5:35 AM
Ipang