Skip to main content

Python Tuple-Introduction


Python Tuple-Introduction   


In Python, a tuple is a collection data type that is similar to a list. However, there are key differences between tuples and lists. The main distinction is that tuples are immutable, meaning once they are created, their elements cannot be changed or modified. In contrast, lists are mutable and can be modified after creation.


Here's a brief introduction to tuples in Python:

 

Creating Tuples:

You can create a tuple by enclosing a comma-separated sequence of values within parentheses ().

# Creating a tuple

my_tuple = (1, 2, 3, 'a', 'b', 'c')

Tuples can also be created without using parentheses, known as tuple packing:

# Tuple packing

my_tuple = 1, 2, 3, 'a', 'b', 'c'

 


Comments