# Creating a tuple
tuple1 = (1, 2, 3, 4, 5)
# Checking membership in a tuple
print(1 in tuple1) # True
print(6 in tuple1) # False
Tuple iteration:
# Creating a tuple
tuple1 = (1, 2, 3, 4, 5)
# Iterating over a tuple
for x in tuple1:
print(x)
Tuple unpacking:
# Creating a tuple
tuple1 = (1, 2, 3)
# Unpacking a tuple
a, b, c = tuple1
print(a) # 1
print(b) # 2
print(c) # 3
Tuple packing and unpacking:
# Packing values into a tuple
tuple1 = 1, 2, 3
# Unpacking a tuple
a, b, c = tuple1
# Repacking values into a new tuple
tuple2 = a, c
print(tuple2) # (1, 3)