Operators
| — Bitwise OR and union
For integers, sets a result bit whenever either input bit is set; two bool operands produce a bool. Sets use | for union, dictionaries for a new merged dictionary (right values replace duplicate keys), and supported type objects for union types. Dictionary and type unions were introduced in Python 3.9 and 3.10 respectively. It does not short-circuit. Custom dispatch uses __or__ and __ror__.
Formal Syntax & Structure
python syntaxpython
left | rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | int, set, dict, type or supporting object | First operand; its type participates in operation selection. |
| right | compatible operand | Second operand; supported values depend on the operand types. |
Return Value
object
Result selected by the operand types and their operation implementations.
Working Example
Example Snippetpython
print(0b0101 | 0b1010)print(sorted({1, 2} | {2, 3}))print({"x": 1} | {"x": 2, "y": 3})print(isinstance("a", int | str))