Python:通过函数更新多个变量

时间:2018-06-27 01:09:35

标签: python-3.x function boolean

我对Python还是很陌生,我想定义一个函数,使我可以将多个变量从True更新为False,反之亦然。甚至可以通过该函数以外的函数重新分配变量吗?

我尝试了多种方式,例如:

alpha = False
beta = False
gamma = False
delta = False

def facing(direction, alpha, beta, gamma, delta):
    if direction == "up":
        alpha = True
        beta = False
        gamma = False
        delta = False
        return (alpha, beta, gamma, delta)

facing('up', alpha, beta, gamma, delta)

if alpha:
    print('alpha')

或:

alpha = False
beta = False
gamma = False
delta = False

def facing(direction, alpha, beta, gamma, delta):
    if direction == "up":
        return alpha == True
        return beta == False
        return gamma == False
        return delta == False


facing('up', alpha, beta, gamma, delta)

if alpha:
    print('alpha')

有没有办法做到这一点?还是我每次想要更改变量时都必须手动将其写出? 提前非常感谢:)

0 个答案:

没有答案