DEV Community

S3CloudHub
S3CloudHub

Posted on

Python IF-ElSE Statement

image alt text here

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.

if statement
if...else statement
if...elif...else statement

  1. Python if statement The syntax of if statement in Python is:

if condition:
# 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

Oldest comments (0)