Professional Documents
Culture Documents
Functions
Functions
Functions
1. Scope
A variable’s scope tells us where in the program it is visible. A variable may have local or global
scope.
Local Scope- A variable that’s declared inside a function has a local scope. In other words, it
is local to that function.
Global Scope- When you declare a variable outside python function, or anything else, it has
global scope. It means that it is visible everywhere within the program.
However, you can’t change its value from inside a local scope(here, inside a function). To do so,
you must declare it global inside the function, using the ‘global’ keyword.
NOTE: The changes reflect back after calling function as for mutable data types by default (call
by refernce method). The changes does not reflect back after calling function as for immutable
data types by default (call by value method)
q=cal(10,20)
print (q)
output is:- (30, -10, 200, 0, 10)
Note :- If function does not have return statement in it then it return None
Passing Parameters to function