Python Control Statements
In Python, the default execution flow of a program is a sequential order. But the sequential order of execution flow may not be suitable for all situations. Sometimes, we may want to jump from line to another line, we may want to skip a part of the program, or sometimes we may want to execute a part of the program again and again. To solve this problem, Python provides control statements.
In Python, the control statements are the statements which will tell us that in which order the instructions are getting executed. The control statements are used to control the order of execution according to our requirements. Python provides several control statements, and they are classified as follows.
Types of Control Statements in Python
In Python, the control statements are classified as follows.
- Selection Control Statements ( Decision Making Statements )
- Iterative Control Statements ( Looping Statements )
Let's look at each type of control statements in Python.
Selection Control Statements in Python
In Python, the selection statements are also known as decision making statements or branching statements. The selection statements are used to select a part of the program to be executed based on a condition. Python provides the following selection statements.
- if statement
- if-else statement
- if-elif statement
- nested if statement
Iterative Control Statements in Python
In Python, the iterative statements are also known as looping statements or repetitive statements. The iterative statements are used to execute a part of the program repeatedly as long as the given condition is True. Using iterative statements reduces the size of the code, reduces the code complexity, makes it more efficient, and increases the execution speed. Python provides the following iterative statements.
- while statement
- for statement
- nested statement