In computer programming, we use the if statement to run a block code only when a certain condition is met.
For example, assigning grades (A, B, C) based on marks obtained by a student.
if the percentage is above 90, assign grade A
if the percentage is above 75, assign grade B
if the percentage is above 65, assign grade C
In Python, there are three forms of the if...else statement.
- Python if statement The syntax of if statement in Python is:
# body of if statement
The if statement evaluates condition.
If condition is evaluated to True, the code inside the body of if is executed.
If condition is evaluated to False, the code inside the body of if is skipped.
How if statement works in Python
Working of if Statement
Top comments (0)