Professional Documents
Culture Documents
Functions PPT Parul
Functions PPT Parul
Functions PPT Parul
Topics covered:
❖ SCOPE of Function Local & Global
❖ Example Programs to explain Local & Global Scope
❖ Global Keyword
❖ Passing Mutable & Immutable arguments to a functions
with Example Programs
❖ Some Board Exam Questions
❖ Flow of Execution
Global Variable is accessible inside as well as outside the
function
What if ,a same
variable is declared
inside as well as
outside the function?
Preference will be given to Local
variable, inside the function
If I want to access a Global
variable within the Local
scope?
Using Global keyword we can
modify the value of a Global
variable within the Local scope
30
20
20
output
B)
Passing Mutable & Immutable Arguments to a Function
Explanation
In this program, tuple, tup is passed
as an argument to the function
func(). In order to perform the
mathematical processing ,it is
required to convert into a list using
the method list(). The next two
statements alter the value of list
and hence the changes are reflected
when these values are displayed.
❖ Changes
made to
the list are
reflected
back after
the
function
calls.
Q1. WAF lenWords(STRING), that takes a string as an argument and returns
a tuple containig length of each word of a string. For eg, if the string is :
“Come let us have some fun”, the tuple will have (4,3,2,4,4,3)
Q2. WAF CountNow(Places) in Python, that takes the dictionary
Places as an argument and displays the names in uppercase of the
places whose names are longer than 5 characters.
Q3. WAF index_List(L) where L the list of elements passed as
argument to the function. The function returns another list
named ‘index list’ that stores the indices of all non-zero
elements of L
1 def greatest(a,b,c):
6 if a>b and a>c:
7. return a FLOW OF
8. elif b>a and b>c: EXECUTION
9. return c
10. else :
11. return c
2. x= int(input(“enter first number”))
3. x= int(input(“enter first number”))
4. x= int(input(“enter first number”)
5. res = greatest(x,y,z)
12. print(res)