Tuples

16 articles
Interview Preparation Intermediate

11.16 Hands-on Exercises

Tuple Operations Practice combining concatenation, membership, and slicing on a single tuple. >>> t = (10, 20, 30) >>> t = …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.15 Interview Questions

Conceptual Questions What’s the difference between a tuple and a list? Why does (1) not create a tuple, but (1,) does? Why are tuples …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.14 Best Practices

When to Use Tuples The data represents a fixed record (coordinates, RGB values, a database row). The value needs to be a dict key or set …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.13 Common Mistakes

Single-Element Tuple Forgetting the trailing comma — (1) is an int, not a tuple (see 11.2 Creating Tuples). This silently produces the wrong …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.12 Tuples in DevOps

Tuples and File Handling Files store plain text, so “reading a tuple” means parsing each line and explicitly reconstructing the …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.11 Common Algorithms

Search and aggregate operations on a tuple use the exact same techniques as on a list (see 10.12 Sorting and Searching and 10.14 Common …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.10 Performance

flowchart TD A["Memory (3 items)"] --> A1["tuple: 64 bytes"] A --> A2["list: 88 bytes"] B["Literal creation speed"] --> B1["tuple: faster"] …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.9 Immutability and Copying

The general mutable-vs-immutable distinction is covered in 5.9 Mutable vs Immutable Types, and general copying mechanics in 6.5 Copying …

Jan 20, 2026 Read more
Interview Preparation Intermediate

11.8 Nested Tuples

Creating and Accessing >>> nested = ((1, 2, 3), (4, 5, 6)) >>> nested[1][2] 6 Updating Nested Mutable Objects A …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.6 Tuple Methods

Tuples have only two methods — a direct consequence of immutability. Every method that would modify a list (append, remove, sort, …; …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.5 Tuple Operators

+ (Concatenation) Combines two tuples into a new tuple — since tuples are immutable, this can never modify either original. >>> (1, …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.4 Tuple Packing and Unpacking

flowchart LR P1["1"] --> PK["packing"] P2["2"] --> PK P3["3"] --> PK PK --> PT["point = (1, 2, 3)"] PT --> UP["unpacking"] UP --> U1["x = …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.3 Tuple Indexing and Slicing

Identical indexing and slicing rules to lists (see 10.3 List Indexing and Slicing) and strings — only the container type, and one copying …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.2 Creating Tuples

Empty Tuple >>> t = () >>> t () Single-Element Tuple A tuple with exactly one element requires a trailing comma — (1) is …

Jan 20, 2026 Read more
Interview Preparation Beginner

11.1 Introduction to Tuples

What Is a Tuple? What Is It? An ordered, immutable collection — like a list, but once created it can never be changed. Written with …

Jan 20, 2026 Read more