Flow of Execution in Python | CBSE Class 12
FLOW OF EXECUTION IN PYTHON
Introduction
In this tutorial, we shell be learning about the flow of execution in python while execution when we write our program through functions in python program.
The flow of execution basically refers to the order in which statements are executed. That is to say, execution always starts at the first statement of the program. Moreover, statements execute one at a time. It happens in order, from top to bottom.
If you are a Python developer or enthusiast, understanding the flow of execution of instructions in Python is crucial for optimizing your code and improving its performance. The flow of execution in Python refers to the order in which statements, functions, and modules are executed in a Python program.
This flow can greatly impact the performance of your code, and understanding it can help you identify and fix potential issues. In this tutorial, we will explore the flow of execution in Python and discuss how you can optimize your code to improve its performance. So, let’s dive into the world of Python programming and understand the flow of execution in Python!
A function makes dramatic changes in control flow that also affects execution time, readability and reusability of our python program.
When a program is executed and the control can take any statement for execution without following the sequence of written program, and completes the required logic behind it, then this random selection of statements execution is called as Functional flow of execution.
Program without functions
Generally, in a simple and basic python program, you see that every python program is executed in a sequential manner that means line by line,
- the first line executed firstly,
- second line executed secondly
and so on to the last line in a Python program but after creating our programs through functions, the functions completely changed its flow of execution. Now see how.
Program with functions
When a python program is written through function, then the control is not going to follow the rule of sequential programming,
that means, now the program is not going to be executed line by line (sequentially) and provides the flexibility to execute any statement at any time required to fulfil the logic of the program.
Now, instead of going to the next statement, and starting from the first, a python program begins with the top level statements according to the logic of program and the flow of control may jumps to the statements required for given logic.
It may also jumps to body of the function and executes all the statements there, and then comes back to pick up where it left off. See the diagram for flow of execution given blow
For more detailed explanation , you can watch these vedeo classes
If we write a program in Python to add two numbers in a then the structure of the Python program will be like this
num1= float(inpit"Entrr first number"))
num2= float(inpit"Entrr second number"))
sum=num1+num2
print (sum)
And , if we write the same program in Python through function then the structure will be like this.
def sum( x,y):
s=x+y
return sum
num1= float(inpit"Entrr first number"))
num2= float(inpit"Entrr second number"))
sum(num1,num2)
print (sum)
Now, compare these steps of execution in both programs.
TABLE OF COMPARISION
S.no | without function | with function |
1 | Line 1 | Line 4 to Line 5 |
2 | Line 2 | Line 6 to Line 1 |
3 | Line 3 | Line 2 to Line 3 |
4 | Line 4 | Line 6 to Line 7 |
That means
Here, you have understood that how the control moves from one line to another following the instruction of program after using functions and this movement/flow of control is known as flow of execution of a program.
Exam Time
Chapter : Flow of execution in python
IMPORTANT QUESTIONS
Asked in examinations of Class 12th Computer Science
—————————————————————————————————————————-
Q1.What are the flow of execution of functions?
Q2.What are the flow of execution of functions in Python?
Q3.What is basic flow of execution?
Q4.What is the function of execute?
Q5.Does Python run functions in order?
Q6.What do you understand by flow of execution in python?
Q7.What is flow of execution in python what does it do with function?
Q8.What are the steps of execution of Python program?
Q9.In python, the flow of execution is altered by the use of which statement?
Q10.What is the basic flow of program execution?
Q11.Explain the order of execution and style of coding in Python?
——————————————————————–
Related Tutorials
——————————————————————————————————————–
Functions in python CBSE Class 12
Arguments and parameters in python CBSE Class 12
Structure program with functions cbse class12
Parameter passing method in python
Also Read in COMPUTER SCIENCE CLASS 12 CBSE
How to Learn Python free online
Syllabus : computer science with python
Also Read in PHYSICS CLASS 12 CBSE
Important Concepts Electrostatic Chapter 2 : Electric potential and capacitance
physics reduced syllabus class 12 cbse 2020-21
Important notes and questions Class 12 Physics : electric charge and electric field