Python Boolean Operations


The basic Boolean operations are and, or, not operations.

  • The and operation − The basic syntax of and operation is: x and y. It indicates that when the x is false, then return x, otherwise returns y.

  • The or operation −The basic syntax of or operation is: x or y. It indicates that when the x is false, then return y, otherwise returns x.

  • The not operation − The basic syntax of and operation is: not x. It indicates that when the x is false, then it returns true, otherwise it returns false.

Example Code

Live Demo

x = 25
y = 18

or_op = x or y
print(or_op)

and_op = x and y
print(and_op)

not_op = not x
print(not_op)

x = 0
not_op = not x
print(not_op)

Output

25
18
False
True

Updated on: 30-Jul-2019

250 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements