Python MCQ’s on Mapping Functions: SET 2

 

11. 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: c
SyntaxError, unbalanced parenthesis.

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

x = [‘ab’, ‘cd’]

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

a) [‘a’, ‘b’, ‘c’, ‘d’]

b) [[‘ab’], [‘cd’]]

c) [[‘a’, ‘b’], [‘c’, ‘d’]]

d) none of the mentioned

Check Answer

Answer: c
Each element of x is converted into a list.

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

x = [12, 34]

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

a) 2

b) 1

c) error

d) none of the mentioned

Check Answer

Answer: c
TypeError, int has no len().

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

x = [12, 34]

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

a) 2

b) 1

c) error

d) none of the mentioned

Check Answer

Answer: a
list(map()) returns a list of two items in this example.

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

x = [12, 34]

print(len(”.join(list(map(int, x)))))

a) 4

b) 2

c) error

d) none of the mentioned

Check Answer

Answer: c
Cannot perform join on a list of ints.

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

x = [12, 34]

print(len(”.join(list(map(str, x)))))

a) 4

b) 5

c) 6

d) error

Check Answer

Answer: a
Each number is mapped into a string of length 2.

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

x = [12, 34]

print(len(‘ ‘.join(list(map(int, x)))))

a) 4

b) 5

c) 6

d) error

Check Answer

Answer: d
TypeError. Execute in shell to verify.

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

x = [12.1, 34.0]

print(len(‘ ‘.join(list(map(str, x)))))

a) 6

b) 8

c) 9

d) error

Check Answer

Answer: c
The floating point numbers are converted to strings and joined with a space between them.

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

x = [12.1, 34.0]

print(‘ ‘.join(list(map(str, x))))

a) 12 1 34 0

b) 12.1 34

c) 121 340

d) 12.1 34.0

Check Answer

Answer: d
str(ab.c) is ‘ab.c’.

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

x = [[0], [1]]

print(len(‘ ‘.join(list(map(str, x)))))

a) 2

b) 3

c) 7

d) 8

Check Answer

Answer: c
map() is applied to the elements of the outer loop.

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