x = ["one", "two", "three", "four"]
x[0]
'one'
x[1]
'two'
x[2]
'three'
len(x)
4
x[len(x) - 1]
'four'
x[-1]
'four'
x[-2]
'three'
x[-3]
'two'
x[-4]
'one'
x[3]
'four'
x[4]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-12-cedd7ac36334> in <module>
----> 1 x[4]
IndexError: list index out of range
x[-5]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-13-3f8aa68a9513> in <module>
----> 1 x[-5]
IndexError: list index out of range
x
['one', 'two', 'three', 'four']
x[-1] = 4
x
['one', 'two', 'three', 4]
type(x[-1])
int
type(x[0])
str
x[0] = x[0].upper()
x
['ONE', 'two', 'three', 4]
x[-1] = "four"
numbers = x
[num.upper() for num in numbers]
['ONE', 'TWO', 'THREE', 'FOUR']
numbers[0]
'ONE'
numbers[0][0]
'O'
numbers[1][2]
'o'
numbers
['ONE', 'two', 'three', 'four']