w3resource
w3resource logo

Python: map() function

(追記) (追記ここまで)
(追記) (追記ここまで)

map() function

The map() function is used to execute a specified function for each item in a iterable.

Version:

(Python 3.2.5)

Syntax:

map(function, iterable, ...)

Parameter:

Name Description Required /
Optional
function Function to be executed. Required
iterable Collection or an iterator object Required

Note: If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel.

Example: Python map() function

def calSqrt(a):
 return a*a
num = (2, 3, 4, 8)
x = map(calSqrt, num)
print(x)
# converting map object to set
numSqrt = set(x)
print(numSqrt)

Output:

<map object at 0x7ff9bbf1f588>
{16, 9, 64, 4}

Python Code Editor:

[フレーム]

PREV : locals()
NEXT : max()

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.

(追記) (追記ここまで)


(追記) (追記ここまで)
(追記) (追記ここまで)


AltStyle によって変換されたページ (->オリジナル) /