Python MCQ Questions - Functions
Python MCQ Questions - This section focuses on "Functions" in Python programming. These python MCQ questions should be practiced to improve the Python programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which keyword is use for function?
A. define
B. fun
C. def
D. function
View Answer
Ans : C
Explanation: Keyword def marks the start of function header. So, option C is correct.
2. Which of the following items are present in the function header?
A. function name
B. parameter list
C. return value
D. Both A and B
View Answer
Ans : D
Explanation: function header consists of function name and parameter list. So, option D is correct.
3. What is called when a function is defined inside a class?
A. class
B. function
C. method
D. module
View Answer
Ans : C
Explanation: method is called when a function is defined inside a class. So, option C is correct.
4. If return statement is not used inside the function, the function will return:
A. None
B. 0
C. Null
D. Arbitary value
View Answer
Ans : A
Explanation: If return statement is not used inside the function, the function will return None. So, option A is correct.
5. 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
View Answer
Ans : B
Explanation: Recursive functions are the functions which calls itself. So, option B is correct.
6. 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
View Answer
Ans : B
Explanation: The id() function returns the identity of the object. This is an integer that is unique for the given object and remains constant during its lifetime. So, option B is correct.
7. 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)
View Answer
Ans : C
Explanation: All required parameters must be placed before any default arguments. Simply because they are mandatory, whereas default arguments are not. Syntactically, it would be impossible for the interpreter to decide which values match which arguments if mixed modes were allowed. A SyntaxError is raised if the arguments are not given in the correct order. So, option C is correct.
8. 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
View Answer
Ans : B
Explanation: Stack, where variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller's environment, such as some of the machine registers, are saved on the stack. So, option B is correct.
9. Which of the following will print the pi value defined in math module?
A. print(pi)
B. print(math.pi)
C. from math import pi
print(pi)
D. from math import pi
print(math.pi)
View Answer
Ans : C
Explanation: from math import pi, print(pi) will print the pi value defined in math module. So, option C is correct.
10. Which operator is used in Python to import modules from packages?
A. .
B. *
C. ->
D. &
View Answer
Ans : A
Explanation: . operator is used in Python to import modules from packages. So, option A is correct.
11. Where is function defined?
A. Module
B. class
C. Another Function
D. All of the above
View Answer
Ans : D
Explanation: Function can be defined in module, class and another function. So, option D is correct.
12. Lambda is a function in python?
A. True
B. False
C. Lambda is a function in python but user can not use it.
D. None of the above
View Answer
Ans : A
Explanation: lambda is an anonymous function in Python. So, option A is correct.
13. What is a variable defined outside a function referred to as?
A. local variable
B. global variable
C. static Variable
D. automatic variable
View Answer
Ans : B
Explanation: Variable defined outside a function is referred as Global variable and can be accessible by other functions. So, option B is correct.
14. What is the output of the following program?
z = lambda x : x * x
print(z(6))
A. 6
B. 36
C. 0
D. error
View Answer
Ans : B
Explanation: This lambda function will calculate the square of a number. So, option B is correct.
15. What is the output of the following program?
print(chr(ord(chr(97))))
A. a
B. A
C. 97
D. error
View Answer
Ans : A
Explanation: Outer chr and ord will cancel out and we will be left with chr(97) which will return "a". So, option A is correct.
16. 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():
View Answer
Ans : C
Explanation: By using def function_name(): we can declared in Python. So option C is correct.
17. 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()
View Answer
Ans : A
Explanation: By using function_name() we can call a function in Python. So option A is correct.
18. Choose the correct option with reference to below Python code?
def fn(a):
print(a)
x=90
fn(x)
A. x is the formal argument.
B. a is the actual argument.
C. fn(x) is the function signature.
D. x is the actual argument.
View Answer
Ans : D
Explanation: x is the actual argument that is the correct option with reference to below Python code. So option D is correct.
19. Which one of the following is incorrect?
A. The variables used inside function are called local variables.
B. The local variables of a particular function can be used inside other functions, but these cannot be used in global space
C. The variables used outside function are called global variables
D. In order to change the value of global variable inside function, keyword global is used.
View Answer
Ans : B
Explanation: The local variables of a particular function can be used inside other functions, but these cannot be used in global space is one of the following is incorrect. So the option B is correct.
20. You can also create your own functions, these functions are called?
A. built-in functions
B. user-defined functions
C. py function
D. None of the above
View Answer
Ans : B
Explanation: Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are called user-defined functions.
21. Function blocks begin with the keyword?
A. define
B. fun
C. function
D. def
View Answer
Ans : D
Explanation: Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
22. The code block within every function starts with a ?
A. ;
B. ::
C. :
D. %
View Answer
Ans : C
Explanation: The code block within every function starts with a colon (:) and is indented.
23. A return statement with _____ arguments.
A. No
B. 1
C. 2
D. Any
View Answer
Ans : A
Explanation: The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.
24. ___________ are the arguments passed to a function in correct positional order.
A. Required arguments
B. Keyword arguments
C. Default arguments
D. Variable-length arguments
View Answer
Ans : A
Explanation: Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.
Also check :
Discussion