I thought they are __and__
and __or__
but turns out they are for bitwise comparisons not logical ones. Are there such methods for the logical comparators?
Asked
Active
Viewed 85 times
3

JRR
- 6,014
- 6
- 39
- 59
-
2I don't think this has changed since the much [earlier question](https://stackoverflow.com/questions/32311518/is-it-possible-to-overload-logical-and-in-python) and the rejected [PEP 335](https://peps.python.org/pep-0335/) – Mark Apr 01 '23 at 06:00
-
Kinda surprising that `and` / `or` / `not` - all 3 aren't implemented using dunder method, wonder if the reason for not implementing logical op that way is part of *"Althought practicality beats purity"* – jupiterbjy Apr 01 '23 at 06:03
-
2It depends what you want to do. Implementing `__bool__` for your class may be the way to go. – buran Apr 01 '23 at 06:03
-
they are implemented as part of the [`operator`](https://docs.python.org/3/library/operator.html#operator.__not__) module. In the link there is this consideration _Note that there is no __not__() method for object instances; only the interpreter core defines this operation._ – cards Apr 01 '23 at 10:29