0% found this document useful (0 votes)
9 views

Working With Functions Question

working with function pyq

Uploaded by

Priya Sohal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Working With Functions Question

working with function pyq

Uploaded by

Priya Sohal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Functions

Ques1) Explain the use of positional parameters in python with the help of suitable example

Ques2) Explain the use of default parameter in python function with the help of example

Ques3)

Ques4)
Ques5)

Ques6)

Ques 7)
Ques8)

Ques9)

Ques10)
Ques 11)

Ques 12) Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the
function. The function returns another list named ‘indexList’ that stores the indices of all Non-Zero
Elements of L.

For example: If L contains [12,4,0,11,0,56] The indexList will have - [0,1,3,5]

Ques 13) Which of the following components are part of a function header in Python?

a. Function Name b. Return Statement c. Parameter List d. Both a and c

Ques 14) Which of the following function header is correct?

a. def cal_si(p=100, r, t=2) b. def cal_si(p=100, r=8, t)

c. def cal_si(p, r=8, t) d. def cal_si(p, r=8, t=2)

Ques 15) Which of the following is the correct way to call a function?

a. my_func() b. def my_func() c. return my_func d. call my_func()

Ques 16)

Ques 17)
Ques 18)

Ques 19)

Ques 20)
Ques 21) Differentiate between actual &a formal parameter with a suitable example in python

Ans)

Actual Parameter Formal Parameter


The list of identifier used in function calling is List of parameters used in function definition is
known as actual parameters known as formal parameter

It can be value/expression/variable It is an identifier

Example :

Def area(len,bre): # here len,bre are formal parameters

Area = len * bre

A=5

B= 2

area(A,B) #A,B are actual parameters

Ques 22) Explain the use of global key word used in a function with the help of a suitable example.

Ans) In Python, global keyword allows the programmer to modify a variable outside the current
scope. It is used mostly in functions to change global scope variable locally . It is writtern inside the
function to us global value of a variable. Outside the function global keyword has no affect

C =10 #global variable

Def Sum(sum):

Global c

C+=sum

Print(C) # it will print 30

Sum(20);

Print(C) # it will also print 30


Ques 23)

Ques 24)

Ques 25)
Ques 26) Assertion (A): In the case of positional arguments, the function call and function definition
statements match in terms of the number and order of arguments.

Reasoning (R): During a function call, positional arguments should precede keyword arguments in
the argument list.

(A)Both A and R are true and R is the correct explanation for A

(B)Both A and R are true and R is not the correct explanation for A

(C)A is True but R is False

(D)A is False but R is True

Ques 27)

Ques 28) Find and write the output of the following python code:

Ques 29) What do you understand by local & global scope of variables ? give example How can you
access global variable inside the function , if function has a variable with same name.
Ques30)

Ques 31) Find the error in the following code snippet

a)

b)
c)

Ques 32)

Ques 33)

Ques 34)

Ques 35)
Ques 36)

Ques 37)

Ques 38)

Ques 39)

Ques 40)

Ques 41)
Ques 42)

You might also like