Create a Tuple
Create a tuple called 'coordinates' with values (100, 200). Print the tuple.
Tuples are like lists, but they cannot be changed (immutable).
Create a tuple:
colors = ("red", "green", "blue")
point = (10, 20)
Access items like lists:
print(colors[0]) # red
print(colors[1]) # green
Tuples are useful for:
- Storing fixed data (coordinates, RGB colors)
- Returning multiple values from functions
- Using as dictionary keys
Unpack tuple values:
x, y = (10, 20)
print(x) # 10
print(y) # 20
Create a tuple called 'coordinates' with values (100, 200). Print the tuple.
Given: rgb = (255, 128, 0) Print each color component on a separate line: - First (red): 255 - Second (green): 128 - Third (blue): 0
Given tuple: point = (50, 75) Unpack it into variables x and y. Print x and y on separate lines.