Logical Operators

 Logical Operators :


There are three types of logical operators:

1. and: True if both conditions are met, otherwise False

2. or: True if either condition is met, otherwise False

3. not: Reverses a True/False value. Converts True to False and False to True.

and logical operator :

‘and’ logic

Condition1

Condition 2

Output

True

True

True

False

True

False

True

False

False

False

False

False



  • If condition1 is True and condition2 is True, result is True.
  • If condition1 is False but condition2 is True, result is False.
  • If condition1 is True but condition2 is False, result is False.
  • If both condition1 and condition2 are False, result is False.
or logical operator :

'or' logic

Condition1

Condition 2

Output

True

True

True

False

True

True

True

False

True

False

False

False


  • If condition1 is True and condition2 is True, result is True.
  • If condition1 is False but condition2 is True, result is False.
  • If condition1 is True but condition2 is False, result is False.
  • If both condition1 and condition2 are False, result is False.


not logical operator :

'not' Logic

Condition

Using not Operator

Output

Condition 1 = True

not condition1

False

Condition 1 = False

Not conditon2

True


The not operator flips the outcome of a condition. For instance :
  • If condition is True, then not condition1 becomes False.
  • Conversely, if condition1 is False, not condition1 turns to True.



code :

time_in_mins=6

condition_to_check=time_in_mins<5

not_condition=not condition_to_check

print(not_condition)

Output :
True


  • You have to must try in your python compiler use idle avoid online compilers to Errors

Post a Comment

0 Comments