Tuples
Not met yet
A tuple is a fixed group of values in round brackets: (112, 98, 84). You read it like a list, with [0] and len(), but you can't change it once it's made. Use one when the parts belong together and shouldn't drift apart: a width, a depth and a height. To change one, build a new tuple.
Try it
main.pyOutput
Press Run and what your program prints shows up here.
Easy to get wrong
- Thinks a tuple can be changed in place, like a list.
- Thinks assigning to an item of a tuple is quietly ignored rather than an error.
- Thinks (84) makes a tuple. Round brackets alone just group; a one-item tuple needs a comma, (84,).
Where it comes up
- Measurement Book
- Lost Property Matcher
- Word Counter and Text Analyser
- Quiz App
- Opening Hours Module
- Log Streamer
- Timing and Retry Decorators
- Weather App
- Speed Tester
- Sorting Visualiser
- Undo/Redo Text Editor
- Hash Map from Scratch
- Parts Catalogue
- Task Scheduler
- Maze Solver
- Route Planner
- Sudoku Solver
- Spell Checker
- Gridworld Simulator
- Value Estimator
- University and Interview Readiness