How to get a single output from a function with multiple outputs?

前端 未结 3 1955
暖寄归人
暖寄归人 2021-01-15 15:40

I have the following simple function:

def divide(x, y):
    quotient = x/y
    remainder = x % y
    return quotient, remainder  

x = divide(22, 7)
<         


        
3条回答
  •  青春惊慌失措
    2021-01-15 16:17

    You are essentially returning a tuple, which is an iterable we can index, so in the example above:

    print x[0] would return the quotient and

    print x[1] would return the remainder

提交回复
热议问题