#Python 的内置函数 map
说明:将可迭代对象进行映射。
#函数说明
def map(fn, iterable, *iterables):
'''
将可迭代对象进行映射
:param fn: 回调函数,返回元素映射后的值
:param iterable: 要映射的可迭代对象
:param iterables: 可变长度的可迭代对象
:return: 映射后的可迭代对象
'''
说明
将可迭代对象进行映射。
参数
fn
- 映射的回调函数,可迭代对象的元素会作为参数传给此函数,此函数的返回值作为映射后的值iterable
- 要映射的可迭代对象iterables
- 可变长度的可迭代对象
返回值
映射后的可迭代对象
#示例
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(map(lambda x : x**2, numbers))
print(list(map(lambda x : x**2, numbers)))