3.4 Comparisons
In Python, comparisons will always return a Boolean, i.e. either True
or False.
We can use the following syntax to compare values:
<
and>
: greater than, less than<=
and>=
: greater than or equal to, less than or equal to
For example:
print(5.3 < 17)
## True
print(4. >= (8/2))
## True
==
checks if two values are equal.!=
checks if two values are different.
print(2 == (10 - 8))
## True
Note that a single equals sign =
is used to assign values. However, a double equals sign ==
is used to compare values.
var1 = 3
sets the variablevar1
to3
var1 == 3
checks whether the value ofvar1
is3