'I can not get python to print a position from a lists/arrays

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?



Solution 1:[1]

array1=["1","2","3"]
print(array1[2])

so index start from 0 so list will always haves length-1 index

Solution 2:[2]

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.

Solution 3:[3]

There are two ways to go about this; one way is to index it positively, and the other 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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hassan Habib
Solution 2 Ann Zen
Solution 3 Mark