I am unsure how to print what is at an index position in an array i.e.
array1 = ["1","2","3"]
if I wanted the program to print 3
what do i do?
CodePudding user response:
There are two ways to go about this; one way is to index it positively, and the otehr is to index it negatively. Observe:
>>> array1 = ["1","2","3"]
>>> print(array1[2])
3
>>> print(array1[-1])
3
The index -1
returns the last element of an array.
CodePudding user response:
Index in python starts from zero. If you want to print “3” in above list, just do print(array1[2])
as “3” is at index 2.
CodePudding user response:
array1=["1","2","3"]
print(array1[2])
so index start from 0 so list will always haves length-1 index