小白教程
所有教程
关于
Search
172.69.58.242
172.69.58.242
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 func map”的源代码
本页内容
上一节:
Python_func_globals
下一节:
Python3_func_reversed
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:map()}}[[Category:python3 built in functions|57]] = Python3 map() 函数 = [[python3 built in functions|Python3 内置函数]] == 描述 == map() 函数会根据提供的函数对指定序列做映射。 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。 === 语法 === 以下是 map() 方法的语法: <sample title="" desc="" lang="python" hererun="1"> map(function, iterable, ...) </sample> === 参数 === * function -- 函数 * iterable -- 一个或多个序列 == 返回值 == 返回一个迭代器。 以下实例展示了 map() 的使用方法: == Python3.x 实例 == <sample title="" desc="" lang="python" hererun="1"> >>> def square(x) : # 计算平方数 ... return x ** 2 ... >>> map(square, [1,2,3,4,5]) # 计算列表各个元素的平方 <map object at 0x100d3d550> # 返回迭代器 >>> list(map(square, [1,2,3,4,5])) # 使用 list() 转换为列表 [1, 4, 9, 16, 25] >>> list(map(lambda x: x ** 2, [1, 2, 3, 4, 5])) # 使用 lambda 匿名函数 [1, 4, 9, 16, 25] >>> </sample> [[python3 built in functions|Python3 内置函数]]
返回至“
Python3 func map
”。
上一节:
Python_func_globals
下一节:
Python3_func_reversed