Introduction to CS | 9.5: Tuple Unpacking: One-Line Swaps and Many Returns

Опубликовано: 11 Август 2026
на канале: Ludium
10
0

Full course — free exercises, Feynman reviews, and AI-graded feedback:
https://ludium.ai/courses/intro-cs-py...

Tuples aren't just for storing data — they unlock two elegant Python moves: swapping two variables in a single line, and returning several results from one function. This video shows how packing and unpacking make both effortless, with no temporary variable to babysit.

Key concepts covered:
The one-line swap x, y = y, x: Python evaluates the whole right side first, then matches by position
Returning a tuple lets a function hand back many values while still returning exactly one object
Retrieving results by index versus unpacking straight into named variables
Integer division and mod working together to return a quotient and remainder
A worked char_counts example that returns vowel and consonant counts as a tuple

━━━━━━━━━━━━━━━━━━━━━━━━
SOURCE MATERIALS
The source materials for this video are from    • Lecture 9: Lambda Functions, Tuples, and L...