Python Logical Operators: and, or, not

Created with Sketch.

Python Logical Operators: and, or, not

We can apply for all types.

For boolean Types Behaviour:
and –> If both arguments are True then only result is True
or –> If at least one arugemnt is True then result is True
not –> Complement
True and False –> False
True or False –> True
not False –> True


For non-boolean Types Behaviour:


0 means False
non-zero means True
empty string is always treated as False
x and y:
If x is evaluated to false return x otherwise return y


Eg:


10 and 20
0 and 20
If first argument is zero then the result is zero otherwise result is y
x or y:
If x evaluates to True then the result is x otherwise result is y
10 or 20 –> 10
0 or 20 –> 20

not x:


If x is evalutates to False then result is True otherwise False
not 10 –> False
not 0 –> True

Eg:

 "mohan" and "mohansoft" ==>durgasoft 
 "" and "mohan" ==>"" 
 "mohan" and "" ==>"" 
 "" or "mohan" ==>"mohan" 
 "mohan" or ""==>"mohan" 
 not ""==>True 
 not "mohan" ==>False 

Leave a Reply

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