Bitwise OR Operator (|)
Bitwise OR Operator
Bitwise OR Operator is used to perform OR operation between two given operands at bit level.
Symbol
The symbol of bitwise OR operator is |
.
Syntax
The syntax to do bitwise OR operation between the operands: x
and y
, is
x | y
Example
The following is a simple example of how bitwise OR operation is done between two numbers.
x = 5
y = 20
#bit level
x = 00000101
y = 00010100
x | y = 00010101
Therefore x | y = 21
In this following program, we take integer values in x
, and y
, and perform bitwise OR operation between them.
Python Program
x = 5
y = 20
output = x | y
print(f'{x} | {y} = {output}')
Output
5 | 20 = 21
Summary
In this tutorial of Python Examples, we learned about Bitwise OR Operator, and it's usage with the help of examples.