DEV Community

Hadijja Musekwa
Hadijja Musekwa

Posted on

Operators and Conditional statements

Operators and conditional statements enable a program to perform calculations, make decisions and respond according to different situations.

Comparison operators

These compare two values and give a Boolean result (True or False).
Common comparison operators are demonstrated in an example below;


You can compare integers and strings, including alphabetical comparisons, but they are case-sensitive.

Arithmetic operators

These perform basic math operations.

Conditional statements

These allow a program to make decisions between possible outcomes.
if statement is used when there's only one possible outcome.
The if...else statement is used when a program needs to choose between possible outcomes.
The __if...elif... else _ _ statement is used when there are more than two possible conditions.
Indentation using a colon (:) at the end of the line indicates that the line belongs to the if statement.

Python uses conditions to determine what should happen in different situations using conditional and operational statements.

Top comments (0)