== | Equal | If first value equal to second value then condition is true |
!= | Not Equal | If first value is NOT equal to second value then condition is true |
< | Less Than | If first value is less than second value then condition is true |
<= | Less Than or Equal | If first value is less than or equal to second value then condition is true |
> | Greater Than | If first value is greater than second value then condition is true |
>= | Greater Than or Equal | If first value is greater than or equal to second value then condition is true |
and | If first value is true AND second value is true then the condition is true | |
or | If first value is true OR second value is true then the condition is true | |
not | If value is not true then the condition is true |
The Compare Operators are used in the if, elif and the while condition statements.
Examples
if 1 == 2: print 'a) you will NEVER see this message' if 1 != 2 : print 'b) you will ALWAYS see this message' if 1 <= 1 : print 'c) you will see this' if (1+2) < (3*(4+5)) and 3 < 23*7: print 'd) you will see this' a = 1 b = 1 c = 1 d = 0 if (a and b) or (c and d): print 'e) you will see this' d = 0 if not d: print 'f) you will see this'