Python MCQ’s on Function: SET 6

51. Python supports the creation of anonymous functions at runtime, using a construct called __________

a) lambda

b) pi

c) anonymous

d) none of the mentioned

Check Answer

Answer: a
Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called lambda. Lambda functions are restricted to a single expression. They can be used wherever normal functions can be used.

52. What will be the output of the following Python code?

y = 6

z = lambda x: x * y

print z(8)

a) 48

b) 14

c) 64

d) None of the mentioned

Check Answer

Answer: a
The lambda keyword creates an anonymous function. The x is a parameter, that is passed to the lambda function. The parameter is followed by a colon character. The code next to the colon is the expression that is executed, when the lambda function is called. The lambda function is assigned to the z variable.
The lambda function is executed. The number 8 is passed to the anonymous function and it returns 48 as the result. Note that z is not a name for this function. It is only a variable to which the anonymous function was assigned.

53. What will be the output of the following Python code?

lamb = lambda x: x ** 3

print(lamb(5))

a) 15

b) 555

c) 125

d) None of the mentioned

Check Answer

Answer: c
None.

54. Does Lambda contains return statements?

a) True

b) False

Check Answer

Answer: b
lambda definition does not include a return statement. it always contains an expression which is returned. Also note that we can put a lambda definition anywhere a function is expected. We don’t have to assign it to a variable at all.

55. Lambda is a statement.

a) True

b) False

Check Answer

Answer: b
lambda is an anonymous function in Python. Hence this statement is false.

56. Lambda contains block of statements.

a) True

b) False

Check Answer

Answer: b
None.

57. What will be the output of the following Python code?

def f(x, y, z): return x + y + z

f(2, 30, 400)

a) 432

b) 24000

c) 430

d) No output

Check Answer

Answer: a
None.

58. What will be the output of the following Python code?

def writer():

title = ‘Sir’

name = (lambda x:title + ‘ ‘ + x)

return name

who = writer()

who(‘Arthur’)

a) Arthur Sir

b) Sir Arthur

c) Arthur

d) None of the mentioned

Check Answer

Answer: b
None.

59. What will be the output of the following Python code?

L = [lambda x: x ** 2,

lambda x: x ** 3,

lambda x: x ** 4]

for f in L:

print(f(3))

a)

27
81
343

b)

6
9
12

c)

9
27
81

d) None of the mentioned

Check Answer

Answer: c
None.

60. What will be the output of the following Python code?

min = (lambda x, y: x if x < y else y)

min(101*99, 102*98)

a) 9997

b) 9999

c) 9996

d) None of the mentioned

Check Answer

Answer: c
None.

Page  1  2  3  4  5  6  7

Python Interview Questions (MCQs)

We have divided these Python Questions and Answers into various parts based on the topics. Open the Topic of your choice and Practice these MCQs.

Python MCQs on Variables and Operators Python MCQs on Precedence and Associativity
Python MCQs on Data Type Python MCQs on Boolean
Python MCQs on Bitwise Operators Python MCQs on Formatting and Advance Formatting
Python MCQs on Decorators Python MCQs on While and For Loops
Python MCQs on List Python MCQs on List Comprehension
Python MCQs on String Python MCQs on Tuple
Python MCQs on SET Python MCQs on Dictionary
Python MCQs on Functions Python MCQs on Argument Parsing
Python MCQs on Global and Local Variables Python MCQs on Recursion
Python MCQs on Mapping Functions Python MCQs on Modules
Python MCQs on Regular Expressions Python MCQs on Files
Python MCQs on Overloading Python MCQs on Classes and Objects
Python MCQs on Inheritance Python MCQs on Polymorphism and Encapsulation
Python MCQs on Exception Handling

Leave a Comment