The Boolean operators in python or bitwise operators in python perform operation on bits(0,1).

Boolean operators in python

  1. AND Operator
  2. OR Operator
  3. NOT Operator
  4. XOR Operator
  5. Shift Left Operator
  6. Shift Right Operator
AND Operator

It performs multiplication on bits and return output as shown in below table. It is represented as “&” symbol in python.

0 and 0
0 & 0
Output: 0
1st Operand 2nd Operand AND(Output)
0 0 0
0 1 0
1 0 0
1 1 1
AND Operator
OR Operator

It performs addition on bits and return output as shown in below table.It is represented by “|” symbol in python.

0 or 1
0 |  1
Output:
1
Operand 1 Operand 2 OR(Output)
0 0 0
0 1 1
1 0 1
1 1 1
OR Operator
NOT Operator

It reverses the bit or it will change 0 to 1 or 1 to 0.

not 0
Output True
not 1
Output False
XOR Operator

It returns output as per below table. It is represented by” ^”.

1 ^ 1
Output:
0
Operand 1 Operand 2 XOR(Output)
0 0 0
0 1 1
1 0 1
1 1 0
XOR Operator
Shift Left Operator

It shifts the bit left by given condition. It is represented as “<<” symbol in python.a has been shifted left by b(one bit) position.

a=1011
b=0001
a<<b
Output:
10110
Shift Right Operator

It shifts the bit right by given condition. It is represented as “>>” symbol in python.a has been shifted right by b(one bit) position.

a=1011
b=0001
a>>b
Output:
0101

 

By SC

Leave a Reply

Your email address will not be published. Required fields are marked *