369 Tesla Logo

Interactive Python Concepts

Created for Kalviyogi Nagarajan - 369 Tesla Pvt Limited

Tuples and Tuple Assignment

Learn about immutable ordered collections and their powerful assignment capabilities

What Are Tuples?

Tuples are immutable, ordered collections of elements in Python, enclosed in parentheses ().

Key Features:

  • Ordered: Elements retain their order and can be accessed by index.
  • Immutable: Tuples cannot be modified after creation.
  • Heterogeneous: Can store elements of different types.
# Creating a tuple
my_tuple = (369, "Tesla", 3.14)
print(my_tuple[0])  # Output: 369
print(my_tuple[1])  # Output: Tesla

Tuple: (369, "Tesla", 3.14)

369
"Tesla"
3.14
Index 0: 369

Everyday Example

Think of a tuple like a fixed recipe. Once you've decided on the ingredients and their order, you can't change them without making a completely new recipe!

Real-world example: Coordinates on a map (latitude, longitude) = (13.0827, 80.2707) for Chennai. The order matters and shouldn't change!