This question originally asked (wrongly) what does ‘|’ mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve.
This question originally asked (wrongly) what does | mean in Python, when the actual
Share
In Python, the
'|'operator is defined by default on integer types and set types.If the two operands are integers, then it will perform a bitwise or, which is a mathematical operation.
If the two operands are
settypes, the'|'operator will return the union of two sets.Additionally, authors may define operator behavior for custom types, so if
something.propertyis a user-defined object, you should check that class definition for an__or__()method, which will then define the behavior in your code sample.So, it’s impossible to give you a precise answer without knowing the data types for the two operands, but usually it will be a bitwise or.