mardi 26 octobre 2021

Multiple conditions in if statements Python [duplicate]

I have a piece of code:

x = 8

if x==3 or 4:
    print("yes")
    
else:
    print("no")

It gives "yes".

I know the correct syntax should be if x==3 or x==4. However, I can't seem to explain the result yielded from the wrong syntax and have tried checking it out on PythonTutor. Why does it result in "yes"?

Aucun commentaire:

Enregistrer un commentaire