Prev | Index | NextList and Tuples Part II -- Examples
>>> best_players = ['fischer', 'kasparov', 'botvinnik']
>>> best_players[0]
'fischer'
>>> best_players[2] = "tal"
>>> best_players
['fischer', 'kasparov', 'tal']
>>> best_players[:2]
['fischer', 'kasparov']
Tuples
>>> foo = ('bar', 234, ['a list inside', 'a tuple!'])
>>> foo[0]
'bar'
>>> foo[0] = "watch out, it's immutable"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
An Introduction To Python