Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Tuples as return types in functions
Tuples as records
List of tuples
Summary
15. Summary – tuples

Instruction

All right, it's time to wrap things up! Let's have a quick summary of what we've learned before we move on:

  1. Tuples are frequently used to return multiple values from a function.
  2. def get_min_max(input_list):
      ...
      return (min, max)
  3. Tuples as function result types are often unpacked into multiple variables.
  4. list_min, list_max = get_min_max(user_list)
  5. Use underscores to ignore certain values.
  6. _, list_max = get_min_max(user_list)
  7. Tuples often represent real-world objects ...
  8. person = ('Mark', 28, 'Spanish')
  9. ... or certain states/positions.
  10. x_y_coordinates = (5, -14)
  11. Tuples are often used in conjunction with lists.
  12. people = [
      ('Mark', 28, 'Spanish'),
      ('Miranda', 21, 'ZEA')
    ]
  13. To compare two lists element by element, we can use the zip() function.
  14. for pair in zip(list_1, list_2):
      if pair[0] == pair[1]:
        ...

Ok! How about a short quiz now?

Exercise

Click Next exercise to continue.