The way to return several variables at once.

Return of Function is an inevitable essence in functional programming. But sometimes functions produce more than one value for return.


In this case, it may be one of the answers to make a list of values.


However, Python has a much more simple solution, which is called 'packing'. It literally means packing independent values into iteration data types.


# Just array values for return.
# Then, the array automatically turns into a tuple of values.

def operations(a, b):
    add = a + b
    sub = a - b
    mul = a * b
    rem = a % b
    return add, sub, mul, rem



a, b = map(int, input().split())

# And so, here is the tuple data type in iterations.
for i in operations(a, b):
    print(i)

좋은 웹페이지 즐겨찾기