Sep-14-2023, 06:11 PM
(This post was last modified: Sep-14-2023, 06:47 PM by deanhystad.)
A or B does not return True or False. A or B returns A if bool(A) is True else it returns B. It doesn't even look at the value of B.
bool(object) is True for most objects. bool(object) is False for False, 0, None, empty list, empty tuple, empty dictionary, empty set and blank string.
(0 or (None or (False or []))) == (None or (False or [])) because bool(0) is False.
(None or (False or [])) == (False or []) because bool(None) is False.
(False or []) == [] because bool(False) is False.
Your code was testing if player == "a".
("a" or "b" or "c" or "d") == "a" because bool("a") is True.
"and" works similarly. A and B returns A if bool(A) is False, else it returns B. It doesn't even look at the value of B.
bool(object) is True for most objects. bool(object) is False for False, 0, None, empty list, empty tuple, empty dictionary, empty set and blank string.
(0 or 5) == 5 (1 or 5) == 1 ([] or None) == None (None or []) == [] (0 or None or False or []) == []Evaluation of the last example.
(0 or (None or (False or []))) == (None or (False or [])) because bool(0) is False.
(None or (False or [])) == (False or []) because bool(None) is False.
(False or []) == [] because bool(False) is False.
Your code was testing if player == "a".
("a" or "b" or "c" or "d") == "a" because bool("a") is True.
"and" works similarly. A and B returns A if bool(A) is False, else it returns B. It doesn't even look at the value of B.
(0 and 5) == 0 (1 and 5) == 5 ([] and None) == [] (None and []) == None (0 and None and False and []) == 0You probably want to use in().
if player not in ("a", "b", "c", "d"): print('whatever') else: breakThis reads better than the equivalent:
if not (player=="a" or player=="b" or player=="c" or player=="d"): print('whatever') else: breakOh, before I forget, your C++ code won't work either. The compiler would complain that you cannot do string || string.