In Python 3, what does map(str, [1, 2, 3]) return?
-
A
The string '123'
-
B
A tuple of strings
-
C
The list ['1', '2', '3']
-
D
A lazy map iterator
Correct answer
Correct answer
D. A lazy map iterator
16 views
Explanation
map() returns an iterator that produces values on demand. Wrap it in list() to see them all. Once consumed, the iterator is exhausted.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ