Tuples
Creating Tuples
empty = ()
numbers = (1, 2, 3)
mixed = (1, "a", 2.5)
packed = "cat", "dog", "rabbit"
cat, dog, rabbit = packedsingle = (1,)Accessing Items
t = (10, 20, 30, 40)
print(t[0]) # 10
print(t[-1]) # 40
print(t[1:3]) # (20, 30)Immutability
Common Methods
Membership and Iteration
When to Use Tuples
Last updated