AND OR and NOT

AND OR and NOT in Python

AND OR and NOT Keywords in Python

A logical operator is a symbol or word used to link two or more expressions in such a way that the value of the generated compound expression depends solely on that of the original expression and the operator’s meaning. Some of the familiar logical operators are AND, OR and NOT.
All  these logical operator returns boolean value

AND Keyword

It is one of the logical operator used to combine conditional statements.

It returns True only if both of the conditions are True else it returns False.

Syntax –

condition1 and condition2
Both conditions in given code is true so if statement executed

a=10
b=5
if(a>2 and b==5):
    print(“AND works fine”)
else:
    print(“It’s not working”)
AND works fine

OR Keyword

It is one of the logical operator used to combine conditional statements.

It returns True if any of the conditions are True else it returns False.

Syntax –

condition1 or condition2

Here a >2 is True but b!=5 is False 

a=10
b=5
if(a>2 or b!=5):
    print(“Hello world!”)
else:
    print(“It’s not working”
Hello world!

NOT Keyword

It returns True if input is False and returns False if input is True

NOT acts like as inverter

Syntax –

not var1

if(not True):
    print(“I am here”)
else:
    print(“I am not there”
I am not there