How does `x, y = y, x` swap two variables in one line, and how does that same pack-then-unpack trick let a single function hand back many values at once?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The given left holds 'red' and right holds 'blue'. Using one tuple-assignment line, trade their values so left ends up with 'blue' and right with 'red'. The final line then packages the pair into swapped.
The one-line swap x, y = y, x
Trace the swap from x = 1 and y = 2, showing the right-hand side evaluating to (2, 1) first and the positional match then leaving x as 2 and y as 1.
Several values returned in one tuple
Write quotient_and_remainder using integer division and the remainder operator, record that quotient_and_remainder(10, 3) hands back (3, 1), and reach its parts with both[0] and both[1].
Unpacking a returned tuple into named variables
Record quote, rem = quotient_and_remainder(5, 2) binding quote to 2 and rem to 1, then used as ordinary variables in the two print lines.
The char_counts exercise
Write the whole function with vowels = 'aeiou', counters set to 0, a for char in s: loop testing char in vowels, and return v, c, checking char_counts('blog') gives (1, 3).