-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions_map().py
31 lines (20 loc) · 897 Bytes
/
Functions_map().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Python map() Function
# Example
# Calculate the length of each word in the tuple:
def myfunc(n):
return len(n)
x = map(myfunc, ('apple', 'banana', 'cherry'))
# Definition and Usage
# The map() function executes a specified function for each item in an iterable. The item is sent to the function as a parameter.
# Syntax
# map(function, iterables)
# Parameter Values
# Parameter Description
# function Required. The function to execute for each item
# iterable Required. A sequence, collection or an iterator object. You can send as many iterables as you like, just make sure the function has one parameter for each iterable.
# More Examples
# Example
# Make new fruits by sending two iterable objects into the function:
def myfunc(a, b):
return a + b
x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))