2.1 - Conditional statements

You can use conditional statements to get a boolean output (either true or false).

Python supports the usual mathematical conditions:

DescriptionPythonMathematical symbol
Equal to==
Not equal to!=
Less than<<
Less than or equal to>=
Greater than>>
Greater than or equal to>=

In the REPL, try different things and see what happens.

>>> "a" == "a"
True
>>> 4 == 6
False
>>> 4 != 6
True
>>> 8 < 9
True
>>> 6 > 1
True
>>> 6 > 7
False
>>> 6 <= 6
True
>>> 6 <= 7
True
>>> 6 <= 5
False
>>> 8 > 4
True
>>> 8 >= 1
True
>>> 8 >= 9
False
>>> 8 > "text" # You cannot do number operations on a string!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '>' not supported between instances of 'int' and 'str'
There was meant to be an ad here. Support us by turning off your ad blocker or donating.