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, like so: "Peter Parker Bruce Wayne Clark Kent". It now becomes considerably harder to extract each person’s name because the first and last names are also separated by spaces. You could use other special characters, such as a comma, to separate full names, but this doesn’t solve the most annoying problem with using strings to store this data: it’s tedious to extract items of interest because you have to keep track of starting and ending indices.