Python Control Statements
The two most commonly used statements in any programming language are as follows :
Sequential statements: These are the statements which are executed one by one.
Control statements: These are the statements that are executed randomly and repeatedly.
Program 1: A Python program to calculate the area of a circle.
import math r = float(input('Enter radius:')) area = math.pi * r**2 print('Area of circle=', area) print('Area of circle= %.2f' %(area))
Here the instructions are executed one by one by the Python interpreter This is called sequential execution. This type of execution is suitable only for developing simple programs. It is not suitable for developing critical programs where complex logic is needed.
- if statement
- if ... else statement
- if ... elif ... else statement
- while loop
- for loop
- else suite
- break statement
- continue statement
- pass statement
- assert statement
- return statement
Please note that the switch statement found in many languages like C and Java is not available in Python.