Paul's Python CoursePPC

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.py

Output

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