Lesson 10. Tuple objects: sequences of any kind of object

After reading lesson 10, you’ll be able to

  • Create a sequence of any kind of object by using a tuple
  • Do a few operations on tuple objects
  • Swap variable values by using tuples

Suppose I give you the simple task of keeping track of your favorite superhero characters. Let’s say you have three: Spiderman, Batman, and Superman.

Using what you know so far, you could try to create a string containing every one of these names, separated by a space, like so: "Spiderman Batman Superman". Using the commands you learned in lessons 7 and 8, you’d be able, with a little effort and care, to keep track of indices in the string and extract each name as needed.

But what if you kept full names in the string, ...

Get Get Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.