12-3 map
# 12-3 map类
# 看看map这个类用在什么场景下!!!
# Q1:求下面列表的数字的平方,组成的新列表
list_x = [1,2,3,4,5,6,7,8]
def square():
return x * x
#方法1:
for x in list_x:
square(x)
# 方法2
list_x = [1,2,3,4,5,6,7,8]
def square(x):
return x * x
r = map(square,list_x)
print(list(r))
#打印结果如图1

网友评论