Logical operators
The Logical operators that we can perform in python are:
- Logical AND (&&)
- Logical OR (||)
- Logical NOT (!)
Logical AND (&&)
The logical AND operator returns True if both the statements are True else returns False.
a=55 if(a>50 and a<100): print("a lies between 50 and 100")Output
a lies between 50 and 100
Logical OR (||)
The logical OR operator returns true if any one of the statements are true and false if both the statements are false.
a=50 if(a>0 or a<0): print("a is either positive or negative") else: print("a is zero")Output
a is either positive or negative
Logical NOT (!)
Logical NOT operator is performed only on single expression. It converts True value to False and False value to True.
a=0 if(a!=0): print("a is either positive or negative") else: print("a is zero")Output
a is zero
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.