Python Programming Primer

Conditional Statements


Like other programming languages, Python has conditional statements that are used to control program execution. In Python, the conditional statements include if, elif, and else.

The following outlines how to use conditional statements in Python.

No files opened Select a file to edit

As the comparison operators, Python comes with the common comparison operators, including ==, !=, >, <, >=, and <=.

No files opened Select a file to edit

Strings in Python are also compared using ==. The following outlines how to use these operators with strings.

No files opened Select a file to edit

In addition, Python has the basic logical operators, including and, or, and not. Contrary to some other languages, these are used in written format (i.e. and instead of && that is used in some other languages).

No files opened Select a file to edit

Loading Exercise...