[Type A] Working with Functions – Chapter 3 Sumita Arora

|
Table of Contents

9. Can a function return multiple values? How?

Solution: Yes, a function can return multiple values by returning them as a tuple or a data structure like a list.

Example Code:

Python
def get_stats(numbers):
    return min(numbers), max(numbers), sum(numbers)

# Call the function and unpack the returned values
numbers = [1, 2, 3, 4, 5]
min_val, max_val, total = get_stats(numbers)
print("Minimum value:", min_val)
print("Maximum value:", max_val)
print("Total sum:", total)
"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *