Example
Tuples vs Lists - Differences
When to use tuples instead of lists? Comparison of properties and applications.
Showing 1–10 of 28
Example
When to use tuples instead of lists? Comparison of properties and applications.
Quiz
Free beginner quiz on Python tuples: 15 questions on indexing, packing and unpacking, count(), index(), slicing and nested tuples. Instant answers.
Example
Tuples are immutable lists. Once created, they cannot be modified.
Example
Tuples have only two methods: count() for counting and index() for searching.
Challenge
…typed commands such as burn 12.5 or set mode safe into tuples and raises ValueError with a reason for anything malformed, then run a whole batch of commands and report each one.
Challenge
Replace three copy-pasted tank-status blocks with a list of (name, level) pairs and one loop, keeping the output exactly the same, then add a fourth tank with a single list item and list the low…
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
Tuple unpacking assigns its elements to separate variables simultaneously.
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.