General Notes

Conditional/Selection Statements

  • Allows a program to make decisions and execute different blocks of code based on certain conditions
  • Selects specific paths depending on the evaluation of boolean expressions

IF Statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Indentation: Lines are indented (usually by three spaces) to indicate that they are contained within a statement in a previous line. Notice how in the condition statements, after the conditions are given, there are some blank spaces

Else Statements

Executes one block if the condition is true, another if it's false.

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Elif Statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Nested If

The same program like above is now being done with nested if statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Pass Statement (Do Nothing)

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Logical Operators

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

CASE Statements

The match-case statement gives a more readable and efficient way to handle multiple conditions

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.