List and explain with syntax and example the flow control statements in Python.

Flow control statements are used to control the order in which instructions are executed in a Python program. These are the basic building blocks of decision-making and looping in Python.


Types of Flow Control Statements in Python:


1. if Statement

Executes a block of code only if the condition is True.

2. if-else Statement

Executes one block of code if the condition is True, and another block if the condition is False.

3. if-elif-else Statement

Allows checking multiple conditions. Only the first True condition’s block gets executed.

Important Notes:

  • All flow control statements end with a colon (:).
  • The block of code following the statement must be indented properly (usually 4 spaces).
  • Use elif (short for else if) when you want to check multiple conditions.
  • Only one block of an if-elif-else chain will execute.

Leave a Reply

Your email address will not be published. Required fields are marked *