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.
Run the program to see the output
As the comparison operators, Python comes with the common comparison operators, including ==
, !=
, >
, <
, >=
, and <=
.
Run the program to see the output
Strings in Python are also compared using ==
. The following outlines how to use these operators with strings.
Run the program to see the output
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).
Run the program to see the output
Loading Exercise...