Example
Tuple Unpacking
Tuple unpacking assigns its elements to separate variables simultaneously.
Showing 1–10 of 28
Example
Tuple unpacking assigns its elements to separate variables simultaneously.
Example
Tuples have only two methods: count() for counting and index() for searching.
Example
When to use tuples instead of lists? Comparison of properties and applications.
Example
Tuples are immutable lists. Once created, they cannot be modified.
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.
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.
Quiz
…types: 15 questions on int, float, str, bool, None, lists, tuples, dictionaries and sets, with instant answers.
Example
Function can return multiple values as a tuple. Unpacking on assignment.
Example
Operator * allows accepting any number of positional arguments.