Python Bitwise AND Operator

Bitwise AND Operator

Bitwise AND Operator is used to perform AND operation between two given operands at bit level.


The symbol of bitwise AND operator is &.


The syntax to do bitwise AND operation between the operands: x and y, is

x & y


The following is a simple example of how bitwise AND operation is done between two numbers.

x = 5
y = 20

# Bit level
    x = 00000101
    y = 00010100
x & y = 00000100

Therefore x & y = 4

In this following program, we take integer values in x, and y, and perform bitwise AND operation between them.

Python Program

x = 5
y = 20
output = x & y
print(f'{x} & {y} = {output}')
Run Code Copy


5 & 20 = 4


In this tutorial of Python Examples, we learned about Bitwise AND Operator, and it’s usage with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍