list(map(int,input().split()))
a = list(map(int, input().split()))
# 创建一个列表,使用 split() 函数进行分割
# map() 函数根据提供的函数对指定序列做映射,就是转化为int型
如果不加map()
报错
Traceback (most recent call last):
File “D:/honggeng/practise/例2.py”, line 11, in
a = int(input().split())
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list’
map()
描述
map() 会根据提供的函数对指定序列做映射。
第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函数返回值的新列表。
语法
map() 函数语法:
map(function, iterable, …)
>>> def square(x) : # 计算平方数
... return x ** 2