ပြင်သစ်ဘာသာ map() ဖိုင်
အမှတ်
计算元组中每个单词的长度:
def myfunc(n): return len(n) x = map(myfunc, ('apple', 'banana', 'cherry'))
定义和用法
map() 函数为 iterable 中的每个项目执行指定的函数。项目作为参数发送到函数。
语法
map(function, iterables)
参数值
参数 | 描述 |
---|---|
function | 必需。为每个项目执行的函数。 |
iterable |
必需。序列、集合或迭代器对象。 您可以发送任意数量的可迭代对象,只需确保该函数的每个可迭代对象都有一个参数即可。 You can send as many iterables as you like, just make sure the function has one parameter for each iterable. |
ပိုမို အမှတ်
အမှတ်
နှစ်ခုစလုံး အပြည့်အဝါ အသုံးပြုပြီး အချက်အလက် အတွက် အသုံးပြု
def myfunc(a, b): return a + b x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))