Can a function in Python return multiple values at once?

0129

Yes, a function in Python can return multiple values at once by separating them with commas. Here's an example:

def return_multiple_values():
    return 1, 2, 3

a, b, c = return_multiple_values()
print(a)  # Output: 1
print(b)  # Output: 2
print(c)  # Output: 3

In this example, the function return_multiple_values returns three values, which are then unpacked into the variables a, b, and c.

0 Comments

no data
Be the first to share your comment!