1. How is a function declared in Python?
A. Def function function_name():
B. Declare function function_name():
C. Def function_name():
D. Declare function_name():
Ans : Def function_name():
2. Which of the following are the two main parts of every function in Python?
A. The function signature and the function corpus
B. The function signature and the function body
C. The function head and the function tail
D. The function heading and the function body
Ans : The function signature and the function body
3. Which of the following is the use of id() function in python?
A. Id() returns the size of object.
B. Id() returns the identity of the object.
C. Both A and B
D. None of the above
Ans : Id() returns the identity of the object.
4. Python function always returns a value
A. False
B. True
Ans : True
5. What is the output of the following function call
def outerFun(a, b):
def innerFun(c, d):
return c + d
return innerFun(a, b)
return a
result = outerFun(5, 10)
print(result)
A. 5
B. 15
C. (15, 5)
D. Syntax Error
Ans : 15
6. Consider the following function:
def square(num):
num_squared = num ** 2
return num_squared
Which of the following lines of codes is the function’s signature?
A. None of these
B. return num_squared
C. def square(num):
D. num_squared = num ** 2
Ans : def square(num):
7. What is the output of the add() function call
def add(a, b):
return a+5, b+5
result = add(3, 2)
print(result)
A. 15
B. 8
C. (8, 7)
D. Syntax Error
Ans : (8,7)
8. What is the output of the following code
def outerFun(a, b):
def innerFun(c, d):
return c + d
return innerFun(a, b)
res = outerFun(5, 10)
print(res)
A. 15
B. Syntax Error
C. (5, 10)
Ans : 15
9. Which of the following function headers is correct?
A. def fun(a = 2, b = 3, c)
B. def fun(a = 2, b, c = 3)
C. def fun(a, b = 2, c = 3)
D. def fun(a, b, c = 3, d)
Ans : def fun(a, b = 2, c = 3)
10. What is a recursive function?
A. A function that calls other function.
B. A function which calls itself.
C. Both A and B
D. None of the above
Ans : A function which calls itself.
11. What is called when a function is defined inside a class?
A. class
B. function
C. method
D. module
Ans : method
12. Which keyword is use for function?
A. define
B. fun
C. def
D. function
Ans : def
13. In which part of memory does the system stores the parameter and local variables of funtion call?
A. Heap
B. Stack
C. Uninitialized data segment
D. None of the above
Ans : Stack
14. Which one of the following is the correct way of calling a function?
A. function_name()
B. call function_name()
C. ret function_name()
D. function function_name()
Ans : function_name()
15. If return statement is not used inside the function, the function will return:
A. None
B. 0
C. Null
D. Arbitary value
Ans : None
0 Comments