mercredi 7 août 2019

there's a better way to recover the parameters of a func inside a IF without calling twice?

I have a piece of code, it's working, but it takes to long to execute, i have made this simplified version to ilustrate my problem

def teste(x):
    if x > 1:
        return x, "whatever", {'foo':'bar'}
    else:
        return False

x = 2

if teste(x):
    a,b,c = teste(x)
else:
    print("false")

there's a better way to do this? i have tried

if(a,b,c = teste(x)):

but i got a syntax error

Aucun commentaire:

Enregistrer un commentaire