Map and lambda function

Hello All

Can you please explain this behaviour ? I am trying to understand the map and lambda function with a simple example

list_ = [1,2,3,4]


list_= map(lambda x: x,list_)


Output is as follows

[1, 2, 3, 4] (This is the output of 1st print statement)
<map object at 0x7f6a16216550> (This is the output of the 2nd print statement)

If I do print(list(list_)) for the second print statement, then I get the required output which prints the list

Why do I require the extra “list” syntax in the print statement ?


The map function returns a map object after applying the function to all elements in the list. This is done to save memory. However, you can display the result as a list by type casting it.