Back

Map Function in Python

Created 1 year ago
73 Views
1 Comments
Svik42X
@Svik42X
Svik42X
@Svik42XProfile is locked. Login

Hi there,

I have a query related to map function.

what is map function and how it used?

what is the difference between "print" and "return" in Python?

In which cases, we can use return?

I give an input to Pycharm IDE:

def myfunc(a, b):

print(a + b)

x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))

print(x)

print(list(x))

Output:

<map object at 0x000001867811EA70>

appleorange

bananalemon

cherrypineapple

[None, None, None]

It shows this output but when I give the same input using print instead of return:

def myfunc(a, b):

return a + b

x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))

print(x)

print(list(x))

Output:
<map object at 0x000002FC7733EA70>

['appleorange', 'bananalemon', 'cherrypineapple']

I noticed this output in one line.

Why it shows different output when I used return and print individually?

Comments
Please login to comment.