Logik Python?

1 Antwort

Von Experte ralphdieter bestätigt

Das ist keine Frage von Python sondern letztlich der Boolschen Algebra.

not ((a and b) or (not a and not b)) # DeMorgan (außen)
!(a and b) AMD !(not a and not b)    # DeMorgan auf Teilterme
(!a or !b) AMD (!!a or !!b)          # [Involution/Doppelneg.]
(!a or !b) AND (a or b)

Und ja, der letzte Term wäre ein XOR, könnte man in Python auch so schreiben:

bool(a) ^ bool(b) # sofern a und b nicht ohnehin boolean sind
a != b #ginge für booleans natürlich auch.