Content · Programming · Python

Python Tuples: Creating Immutable Sequences

Tuples are ordered sequences whose element references cannot be reassigned. Parentheses are common notation, but the comma creates a tuple in most expressions. See two practical examples, edge cases and common mistakes.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

A sensor reading pairs latitude and longitude values that belong together.

What You Need to Understand


Tuples are ordered sequences whose element references cannot be reassigned. Parentheses are common notation, but the comma creates a tuple in most expressions.

When to Use It


A sensor reading pairs latitude and longitude values that belong together.

Step-by-Step Python Example


location = (32.08, 34.78)
print(location[0])
print(len(location))
print(type(location).__name__)

How the Example Works


Indexing works like a list, but assigning to location[0] would raise TypeError.

Example Output


32.08
2
tuple
120 80 30

A Second Example


Compare this smaller variation with the main example, then experiment with your own values.

rgb = (120, 80, 30)
red, green, blue = rgb
print(red, green, blue)

Important Behavior and Edge Cases


Tuple immutability is shallow: a mutable object stored inside a tuple can still change.

Try It Yourself


Store a fixed RGB color as a tuple and unpack it into three variables.

Common Beginner Mistakes


  • Tuple immutability is shallow: a mutable object stored inside a tuple can still change.
  • Assuming every sequence operation modifies the original data or that a tuple makes nested mutable objects immutable.

Key Takeaways


  • Tuples are ordered sequences whose element references cannot be reassigned.
  • Indexing works like a list, but assigning to location[0] would raise TypeError.
  • Tuple immutability is shallow: a mutable object stored inside a tuple can still change.
Share this resourceSend this page to someone who may find it useful.