4 ms·
Woah! I was all ready to disagree with you, saying 'only for Boolean arguments'. In years of writing python I really thought `__and__`/`__or__` returned Boolea
by OJFord 5y ago
Woah! I was all ready to disagree with you, saying 'only for Boolean arguments'. In years of writing python I really thought `__and__`/`__or__` returned Boolean. (Of course they can, but for builtins I mean.)
https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types https://docs.python.org/3/reference/datamodel.html#emulating...
It's not made clear here that I can see. Grr, needs type annotations!
- maweki 5y agoThat's the wrong part of the doc. You refer to the binary operators || and &&, etc. This is the correct part: https://docs.python.org/3/reference/expressions.html?highlight=operators#boolean-operations https://docs.python.org/3/reference/expressions.html?highlig... Edit: you can't override "and" and "or" with dunder methods.
- OJFord 5y agoAhh of course, thanks!
- jazzyjackson 5y agoSee the language around short-circuiting here https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not https://docs.python.org/3/library/stdtypes.html#boolean-oper... The expression is returned based on its truthiness