Python Questions and Answers – Mapping Functions – 3

This set of Python Interview Questions and Answers for freshers focuses on “Mapping Functions”.

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

x = [[0], [1]]
print((' '.join(list(map(str, x)))))

a) (‘[0] [1]’,)
b) (’01’,)
c) [0] [1]
d) 01
View Answer

Answer: c
Explanation: (element) is the same as element. It is not a tuple with one item.
advertisement
advertisement

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

x = [[0], [1]]
print((' '.join(list(map(str, x))),))

a) (‘[0] [1]’,)
b) (’01’)
c) [0] [1]
d) 01
View Answer

Answer: a
Explanation: (element,) is not the same as element. It is a tuple with one item.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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

advertisement
x = [34, 56]
print((''.join(list(map(str, x))),))

a) 3456
b) (3456)
c) (‘3456’)
d) (‘3456’,)
View Answer

Answer: d
Explanation: We have created a tuple with one string in it.
advertisement

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

x = [34, 56]
print((''.join(list(map(str, x)))),)

a) 3456
b) (3456)
c) (‘3456’)
d) (‘3456’,)
View Answer

Answer: a
Explanation: We have just created a string.

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

x = [34, 56]
print(len(map(str, x)))

a) [34, 56]
b) [’34’, ’56’]
c) 34 56
d) error
View Answer

Answer: d
Explanation: TypeError, map has no len.

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

x = 'abcd'
print(list(map(list, x)))

a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘abcd’]
c) [[‘a’], [‘b’], [‘c’], [‘d’]]
d) none of the mentioned
View Answer

Answer: c
Explanation: list() is performed on each character in x.

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

x = abcd
print(list(map(list, x)))

a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘abcd’]
c) [[‘a’], [‘b’], [‘c’], [‘d’]]
d) none of the mentioned
View Answer

Answer: d
Explanation: NameError, we have not defined abcd.

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

x = 1234
print(list(map(list, x)))

a) [1, 2, 3, 4]
b) [1234]
c) [[1], [2], [3], [4]]
d) none of the mentioned
View Answer

Answer: d
Explanation: TypeError, int is not iterable.

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

x = 1234
print(list(map(list, [x])))

a) [1, 2, 3, 4]
b) [1234]
c) [[1], [2], [3], [4]]
d) none of the mentioned
View Answer

Answer: d
Explanation: TypeError, int is not iterable.

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

x = 'abcd'
print(list(map([], x)))

a) [‘a’, ‘b’, ‘c’, ‘d’]
b) [‘abcd’]
c) [[‘a’], [‘b’], [‘c’], [‘d’]]
d) none of the mentioned
View Answer

Answer: d
Explanation: TypeError, list object is not callable.

11. Is Python code compiled or interpreted?
a) Python code is only compiled
b) Python code is both compiled and interpreted
c) Python code is only interpreted
d) Python code is neither compiled nor interpreted
View Answer

Answer: b
Explanation: Many languages have been implemented using both compilers and interpreters, including C, Pascal, and Python.

12. Which of these is the definition for packages in Python?
a) A folder of python modules
b) A set of programs making use of Python modules
c) A set of main modules
d) A number of files containing Python definitions and statements
View Answer

Answer: a
Explanation: A folder of python programs is called as a package of modules.

13. Which of these is false about a package?
a) A package can have subfolders and modules
b) Each import package need not introduce a namespace
c) import folder.subfolder.mod1 imports packages
d) from folder.subfolder.mod1 import objects imports packages
View Answer

Answer: b
Explanation: Packages provide a way of structuring Python namespace. Each import package introduces a namespace.

Sanfoundry Global Education & Learning Series – Python.

To practice all interview questions on Python for freshers, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.