Logical operators

Logical operators

Logical operators are used to combine conditional statements. In logic, they are called logical connectives. These are also widely used in human language. These operators are the and, or, not operators.

and ==>	Logical AND : True if both the operands are true
or 	==> Logical OR : True if either of the operands is true
not ==>	Logical NOT : True if operand is false

We can apply these operators for all types.

For boolean Types

True and False ==> False 
True or False ==> True 
not False ==>True

For non-boolean Types

0 means False 
non-zero means True 
empty string is always treated as False
x and y

If x is evaluates to false return x otherwise return y.

E.g

10 and 20 
0 and 20

If first argument is zero then result is zero otherwise result is y.

x or y

If x evaluates to True then result is x otherwise result is y.

10 or 20 ==> 10 
0 or 20 ==> 20
not x

If x is evaluates to False then result is True otherwise False.

not 10 ==> False 
not 0 ==> True

E.g

"ashok" and "ashokkumar" ==> ashokkumar 
"" and "ashok" ==> "" 
"ashok" and "" ==> ""
"" or "ashok" ==> "ashok"
"ashok" or "" ==> "ashok"
not "" ==> True
not "ashok" ==> False
Logical operators


Scroll to top