Python Boolean Operations

PythonProgrammingServer Side Programming

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
raja
Published on 30-Oct-2018 16:25:55
Advertisements