Example
Tuple Unpacking
Tuple unpacking assigns its elements to separate variables simultaneously.
7 results
Example
Tuple unpacking assigns its elements to separate variables simultaneously.
Quiz
Free beginner quiz on Python tuples: 15 questions on indexing, packing and unpacking, count(), index(), slicing and nested tuples. Instant answers.
Challenge
Unpack an (id, item, mass_kg) tuple into three named variables and print a cargo manifest line, then fix the ValueError when the manifest adds a fourth field.
Example
Function can return multiple values as a tuple. Unpacking on assignment.
Challenge
Store the Perseverance landing site as a (lat, lon) tuple, unpack it into two variables in one line and print both to four decimals, then show it the way maps do, with N, S, E and W.
Challenge
…The whole pass: 419.5 Inside the function, values is a tuple, so sum() and len() work on it. In the second call, average(*readings) passes the five readings as five separate arguments. An option after…
Quiz
…*args and **kwargs: 15 questions on extra arguments, tuples, dictionaries, and * and ** in calls. Instant answers.