您有两种主要选择:
修改该函数以适当返回一个或两个,例如:
def divide(x, y, output=(True, True)):quot, rem = x // y, x % yif all(output): return quot, remelif output[0]: return quotreturn rem
quot = divide(x, y, (True, False))
保留该函数不变,但显式忽略其中一个返回值:
quot, _ = divide(x, y) # assign one to _, which means ignore by convention
rem = divide(x, y)[1] # select one by index
我强烈建议使用后一种说法;这 要 简单得多!



