Social Media

12/22/2018

Logical Operators

There are 3 logical operators available in Python.
and, or , not.

Operator
Expression
Explanation
anda>b and a<cBoth true then true
ora>b and a<cAny one true then true
notnot a>bInvert the result


3>4 and 5>6  #False
3 or 4 #3
3 and 4 #4
Empty string is treated as False.
Non empty strings are treated as true.
The important points to be noted are as follows:
  •  x and y: If x and y are not boolean then  result is not boolean. If x is False then result is x otherwise result is y.
  •  x or y: If x and y are not boolean here,then result is also not boolean. If x is False result is y otherwise result is x. eg 0 or 5 result is 5
Be First to Post Comment !
Post a Comment