FUNCTION
FUNCTION
A function is defined as a group of statements that can be invoked from any part of the
program for the purpose of performing a specific task.
Alternative names
Function /Method/Procedure/Routine/Sub-routine/Sub-program.
Example
Flow of execution refers to the order in which statements are executed during a program
run.
1567128
ERROR
Keyword / Named Argument : In keyword argument, we can write any argument
in any order provided we name the argument.
NOTE : The return statement ends a function execution even if it is in the middle of the
function.
Functions not returning any value / void functions / Non – fruitful functions :
These functions do not return any computed value.
It may or may not have a return statement, but if it has, then it takes the
following form :
return
Scope of Variables : It refers to the part of program within which a name is legal and
accessible. It is of two types :
Global scope : A name declared in a top – level segment (__main__) of a program
is said to have a global scope.
Local scope : A name declared in a function body is said to have a local scope.
Example :
a1, b1 and result are Global variables
a,b and c are local variables
Lifetime of a variable : The time for which a variable remains in memory is called lifetime
of a variable.
For global variables, lifetime is entire program run.
For local variables, lifetime is their function’s run.
Example :