mardi 30 juin 2020

Python if not but also not that or that [duplicate]

Im trying to check if a list is empty and a variable is not filled with neither of two strings. Thats my code:

var = "random"
my_list = []

if not my_list and (var != 'String1' or var != 'String2'):
    return False
else:
    return True

The part which checks if the list is empty works, but how can i add the second condition with the variable? I tried a few version but none of them works. This one i found makes the most sense to me but it doesnt work. Should not be that hard but i cant seem to figure it out.

My expectiation is: If my_list is empty and var is not 'String1' or 'String2' the Condidion should be true and return False (Like in that code sample) How can i accomplish that?

Aucun commentaire:

Enregistrer un commentaire