0% found this document useful (0 votes)
57 views3 pages

Function (Worksheet)

The document contains a series of practice questions related to functions in Python, covering topics such as return values, function headers, parameter passing, and variable scope. Each question presents multiple-choice answers to test knowledge on Python function syntax and behavior. It serves as a study guide for individuals looking to enhance their understanding of Python functions.

Uploaded by

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

Function (Worksheet)

The document contains a series of practice questions related to functions in Python, covering topics such as return values, function headers, parameter passing, and variable scope. Each question presents multiple-choice answers to test knowledge on Python function syntax and behavior. It serves as a study guide for individuals looking to enhance their understanding of Python functions.

Uploaded by

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

Practice questions of function in

Python

1. If return statement is not used inside the function, the function will return:
a. 0
b. None object
c. an arbitrary integer
d. Error! Functions in Python must have a return statement.
2.Which of the following keywords marks the beginning of the function block?
a. func
b. define
c. def
d. function
3.What is the area of memory called, which stores the parameters and local variables of a function call ?
a. a heap
b. storage area
c. a stack
d. an array
4. Find the errors in following function definitions :
1.def main()
print ("hello")
2.def func2():
print(2 + 3)
3. def compute():
print (x * x)
4.square (a)
return a * a
5.What is the default return value for a function that does not return any value explicitly ?
a. None
b. int
c. double
d. null
6.Which of the following items are present in the function header?
a. function name only
b. both function name and parameter list
c. parameter list only
d. return value
7.Which of the following colon marks the declaration of the function?
a. :
b. ;
c. /
d. [ ]
8.What is the name given to that area of memory, where the system stores the parameters and local variables
of a function call?
a. a heap
b. storage area
c. a stack
d. an array
9.Pick one the following statements to correctly complete the function body in the given code snippet.
def f(number):
#Missing function body
print(f(5))
a. return "number"
b. print(number)
c. print("number")
d. return number
10.Which of the following function headers is correct ?
a. def f(a = 1, b):
b. def f(a = 1, b, c = 2):
c. def f(a = 1, b = 1, c = 2):
d. def f(a = 1, b = 1, c = 2, d):
11.Which of the following statements is not true for parameter passing to functions ?
a. You can pass positional arguments in any order.
b. You can pass keyword arguments in any order.
c. You can call a function with positional and keyword arguments.
d. Positional arguments must be before keyword arguments in a function call.
12.Which of the following is not correct in context of Positional and Default parameters in Python functions?
a. Default parameters must occur to the right of Positional parameters.
b. Positional parameters must occur to the right of Default parameters.
c. Positional parameters must occur to the left of Default parameters.
d. All parameters to the right of a Default parameter must also have Default values.
13.Which of the following is not correct in context of scope of variables?
a. Global keyword is used to change value of a global variable in a local scope.
b. Local keyword is used to change value of a local variable in a global scope.
c. Global variables can be accessed without using the global keyword in a local scope.
d. Local variables cannot be used outside its scope.
14.Which of the following function calls can be used to invoke the below function definition?
def test(a, b, c, d)
a. test(1, 2, 3, 4)
b. test(a = 1, 2, 3, 4)
c. test(a = 1, b = 2, c = 3, 4)
d. test(a = 1, b = 2, c = 3, d = 4)
15.For a function header as follows :
def Calc(X,Y = 20):
Which of the following function calls will give an error?
a. Calc(15, 25)
b. Calc(X = 15, Y = 25)
c. Calc(Y = 25)
d. Calc(X = 25)
16.What is a variable defined outside all the functions referred to as?
a. A static variable
b. A global variable
c. A local variable
d. An automatic variable
17.What is a variable defined inside a function referred to as
a. A static variable
b. A global variable
c. A local variable
d. An automatic variable
18.Carefully observe the code and give the answer.
def function1(a):
a = a + '1'
a=a*2
>>>function1("hello")
a. indentation Error
b. cannot perform mathematical operation on strings
c. hello2
d. hello2hello2
19.What is the result of this code?
def print_double(x):
print(2 ** x)
print_double(3)
a. 8
b. 6
c. 4
d. 10

You might also like