Learning Python: Part 5: Conditional Statements

Learning Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.

Conditional Statements

Similar to assignment statements (where values are set) and expression statements (where something is “expressed”), there are also conditional statements.

If Python, a statement is conditional if the result of it is either True or False. These are Boolean values, named after George Boole.


The keyword if tests if some conditional statement is true or not. If it is True, some code is run. If it is not, the code is skipped.

If… else

The else statement runs if the if statement is not true. This works as an alternative to the if statement.


When testing if a conditional statement is True or not, there are a number of different comparisons.

  • Less-than (<)
  • Greater-than (>)
  • Equal (==)
  • Not equal (!=)
  • Less-than-or-equal-to (<=)
  • Greater-than-or-equal-to (>=)

Play with the example on Repl.it!