Control Flow In Python

Share via:
CONTROL FLOW

Decision making statements in programming languages decide the direction of the flow of program execution based on the given conditions.

Python supports if, Elif used to decide the flow of execution.

If statement:

It is the basic decision-making statement, in this the code will be executed based on the given condition.it is having a code body that only executes when the given condition is true.

Under one if there might be single or multiple statements executed based on given condition

Syntax:

Python uses indentation to identify a block so, the block under an if statement will be executed if the condition is true.

Flowchart of if in python

Example

OUTPUT

if- else:

There exist two blocks of code one for if the condition is True other if the condition is False.

We can use the else statement with if statement to execute a block of code when the condition is False.

Syntax:

Flowchart of if else in python

Example

OUTPUT

Nested if

An if statement inside another if statement is known as nested if.

Syntax

Example

Output:

if -elif-else ladder

In Python, the if-elif-else condition statement has an elif block to chain multiple conditions one after another. This is useful when you need to check multiple conditions.

Syntax:

Example

Output

Author    : Teja

LinkedIn : https://www.linkedin.com/in/teja-sai-nadh-reddy-tatireddy-048882201

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTExperts is always active on social media platforms.

Facebook  : https://www.facebook.com/ktexperts/
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Add Comment