dimanche 28 mars 2021

Unexpected behavior in multiple condition if statement

In the following code, I expect to see yes and no in the output, respectively, but the opposite happens.

>>> if 'a' or 'b' in 'c':
>>>     print('yes')
>>> else:
>>>     print('no')
yes # I expect no

also:

>>> if ('a' or 'b') in 'b':
>>>     print('yes')
>>> else:
>>>     print('no')
no # I expect yes

Why does this happen?

Aucun commentaire:

Enregistrer un commentaire