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

Instruction

Very good! First of all, tuples are typically used to return multiple values from a single function. Take a look:

def count_spaces_commas_stops(text):
  spaces, commas, stops = 0, 0, 0 
  for letter in text:
    if letter == ' ':
      spaces += 1
    elif letter == ',':
      commas += 1
    elif letter == '.':
      stops += 1
  return (spaces, commas, stops)

The above function accepts a string argument named text and returns a tuple with three elements: the count of spaces in the text, the count of commas, and the count of full stops.

Exercise

Create a function named get_min_max_mean(numbers) that accepts a list of integer values and returns the smallest element, the largest element, and the average value respectively – all of them in the form of a tuple.

You can use the template code to test your function.

Stuck? Here's a hint!

Use the following for loop:

for number in numbers: