Python MCQs on Mapping Functions: SET 1

Python MCQs on Mapping Functions

In this section, we are going to introduce you to the most frequently asked Python MCQs on Mapping Functions. These Python MCQs on Mapping Functions will be going to help you in Interviews and Exams.

 

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

elements = [0, 1, 2]

def incr(x):

return x+1

print(list(map(elements, incr)))

a) [1, 2, 3]

b) [0, 1, 2]

c) error

d) none of the mentioned

Check Answer

Answer: c
The list should be the second parameter to the mapping function.

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

elements = [0, 1, 2]

def incr(x):

return x+1

print(list(map(incr, elements)))

a) [1, 2, 3]

b) [0, 1, 2]

c) error

d) none of the mentioned

Check Answer

Answer: a
Each element of the list is incremented.

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

x = [‘ab’, ‘cd’]

print(list(map(upper, x)))

a) [‘AB’, ‘CD’]

b) [‘ab’, ‘cd’]

c) error

d) none of the mentioned

Check Answer

Answer: c
A NameError occurs because upper is a class method.

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

def to_upper(k):

return k.upper()

x = [‘ab’, ‘cd’]

print(list(map(upper, x)))

a) [‘AB’, ‘CD’]

b) [‘ab’, ‘cd’]

c) none of the mentioned

d) error

Check Answer

Answer: d
A NameError occurs because upper is a class method.

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

def to_upper(k):

return k.upper()

x = [‘ab’, ‘cd’]

print(list(map(to_upper, x)))

a) [‘AB’, ‘CD’]

b) [‘ab’, ‘cd’]

c) none of the mentioned

d) error

Check Answer

Answer: a
Each element of the list is converted to uppercase.

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

def to_upper(k):

k.upper()

x = [‘ab’, ‘cd’]

print(list(map(to_upper, x)))

a) [‘AB’, ‘CD’]

b) [‘ab’, ‘cd’]

c) none of the mentioned

d) error

Check Answer

Answer: c
A list of Nones is printed as to_upper() returns None.

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

x = [‘ab’, ‘cd’]

print(map(len, x))

a) [‘ab’, ‘cd’]

b) [2, 2]

c) [‘2’, ‘2’]

d) none of the mentioned

Check Answer

Answer: d
A map object is generated by map(). We must convert this to a list to be able to print it in a human readable form.

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

x = [‘ab’, ‘cd’]

print(list(map(len, x)))

a) [‘ab’, ‘cd’]

b) [2, 2]

c) [‘2’, ‘2’]

d) none of the mentioned

Check Answer

Answer: b
The length of each string is 2.

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

x = [‘ab’, ‘cd’]

print(len(map(list, x)))

a) [2, 2]

b) 2

c) 4

d) none of the mentioned

Check Answer

Answer: d
A TypeError occurs as map has no len().

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

x = [‘ab’, ‘cd’]

print(len(list(map(list, x))))

a) 2

b) 4

c) error

d) none of the mentioned

Check Answer

Answer: a
The outer list has two lists in it. So it’s length is 2.

Page  1  2  3

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