0

I am looking through the internet and I don't seem to find the right answer. In PyCharm it highlights the dunder methods when you define one. So I tried __or__ and it highlighted it purple. Then I thought "maybe this is the one", but with a lot of thinking I faced the hard way that __or__ is for |. So how do I override the or operator?

stackprotector
  • 10,498
  • 4
  • 35
  • 64
Sha7r
  • 145
  • 2
  • 11
  • 1
    You *cannot* override the `or` (or `and`) operators. They return without evaluating all the operands (this is called "short-circuiting") as soon as the outcome becomes definite; this is an absolutely critical feature of these operators - and completely impossible to duplicate with a function call. – jasonharper Jun 13 '20 at 15:22
  • aww ok, please make that an answer so I can mark it solved, thnx – Sha7r Jun 13 '20 at 16:37
  • Well, there are workarounds. Does [this](https://stackoverflow.com/q/15008807/11942268) help? – stackprotector Jun 14 '20 at 08:57
  • um.. well I don't want to use '|' I have it for a different purpose I need to use 'or' – Sha7r Jun 14 '20 at 16:43

0 Answers0