Tuples

Tuples are similar to lists, but they are immutable, which means their elements cannot be changed. Tuples are created using parentheses ().

# Creating a tuple of integers
my_tuple = (1, 2, 3, 4, 5)

# Creating a tuple of strings
my_strings = ("apple", "banana", "cherry")

 

Tuples can be accessed and sliced in the same way as lists, using their index.

# Accessing elements of a tuple
print(my_tuple[0])  # Output: 1
print(my_strings[2])  # Output: "cherry"

Tuples are often used to represent fixed data structures, such as geographic coordinates, or as function arguments and return values.

Python Data Structures : https://learndataengineeringskills.com/python-data-structure-lists/#more-369

Leave a Comment