Indexing Tuples

suggest change
x = (1, 2, 3)
x[0]  # 1
x[1]  # 2
x[2]  # 3
x[3]  # IndexError: tuple index out of range

Indexing with negative numbers will start from the last element as -1:

x[-1] # 3
x[-2] # 2
x[-3] # 1
x[-4] # IndexError: tuple index out of range

Indexing a range of elements

print(x[:-1])   # (1, 2)
print(x[-1:])   # (3,)
print(x[1:3])   # (2, 3)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents