Search⌘ K
AI Features

Introduction to Tuples

Explore Python tuples to understand their use for storing dissimilar data. Learn how to create, access, slice, and loop through tuples using indexing and built-in functions like enumerate. Gain practical skills in handling tuples effectively for programming tasks.

What is a tuple?

Though a list can store dissimilar data, it is commonly used for storing similar data.

The tuple is commonly used for storing dissimilar data. The tuple data is enclosed within () as shown below:

Python 3.8
a = ( ) # empty tuple
b = (10,) # tuple with one item. , after 10 is necessary
c = ('James', 25, 34555.50) # tuple with dissimilar items
d = (10, 20, 30, 40) # tuple with similar items
print(a)
print(b)
print(c)
print(d)

Note: In the code above, while ...