What is Tuples?

In Python, a tuple is a collection of immutable (unchangeable) elements.

my_tuple = (1, 2, 3, "hello", 5.0)

Lists vs Tuples

Lists are mutable. They can be modified after creation.

Tuples are immutable. Once created, their content cannot be changed.

download (1).png

Characteristics:

print(my_tuple[0])  
**# Output: 1**

print(my_tuple[3])  
**# Output: hello**

If you try to change a value, you'll get an error:

my_tuple[1] = 10 

**# This will raise an error because tuples are immutable**