Python Tuples

 

Python Tuples

Tuples are ordered collection of data items. They store multiple items in a single variable. Tuple items are separated by commas and enclosed within round brackets (). Tuples are unchangeable meaning we can not alter them after creation.

 

Example 1:

tuple1 = (1,2,2,3,5,4,6)
tuple2 = ("Red", "Green", "Blue")
print(tuple1)
print(tuple2)

Output:

(1, 2, 2, 3, 5, 4, 6)
('Red', 'Green', 'Blue')

 

Example 2:

details = ("Maxon", 18, "FYBScIT", 9.8)
print(details)

Output:

('Maxon', 18, 'FYBScIT', 9.8)