Python - Comparisons AND Booleans

Booleans



Another type in Python is the Boolean type. There are two Boolean values: True and False.
They can be created by comparing values, for instance by using the equal operator ==.


>>> 1 == 1 and 2 == 2
True
>>> 1 == 1 and 2 == 3
False


Python uses words for its Boolean operators, whereas most other languages use symbols such as &&, || and !.



Comparison

------------------------------

Python also has operators that determine whether one number (float or integer) is greater than or smaller than another. These operators are > and < respectively.

>>> 8 > 6
True
>>> 11 < 11
False

------------------------------


The greater than or equal to, and smaller than or equal to operators are >= and <=.
They are the same as the strict greater than and smaller than operators, except that they return True when comparing equal numbers.
>>> 8 <= 8
True
>>> 10 >= 10.0
True

Greater than and smaller than operators can also be used to compare strings lexicographically (the alphabetical order of words is based on the alphabetical order of their component letters).





Comments

Popular posts from this blog

Python - How to Escape special characters in String

Python - Argument Passing