3. Indexes

3.1. Accessing element with index

  • Index must be positive or negative int

  • Index must be less or equal to length of object

  • Negative index starts from the end and go right to left

3.2. Accessing element from start

text = 'We choose to go to the Moon!'

text[0]         # 'W'
text[1]         # 'e'
text[23]        # 'M'

3.3. Accessing element from back

text = 'We choose to go to the Moon!'

text[-1]        # '!'
text[-5]        # 'M'

3.4. Accessing not existing element

text = 'We choose to go to the Moon!'

text[100]
# IndexError: string index out of range

3.5. Assignments

Todo

Create Assignments