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

前端 未结 3 1956
暖寄归人
暖寄归人 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:32

    You can either unpack the return values when you call your method:

    x, y = divide(22, 7)
    

    Or you can just grab the first returned value:

    x = divide(22, 7)[0]
    

提交回复
热议问题