Python Programming MCQ - Function
16. 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.
17. 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.
18. 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.
19. 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.
20. 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.
21. 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.
22. 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.
23. 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.
24. 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.
Also check :
Discussion