map


x_list = [1,2,3,4,5,6,7,8,9]

def square(x):
     return x*x

r = map(square,x_list)

print(r)
print(list(r))
<map object at 0x7fded01b8d90>
[1, 4, 9, 16, 25, 36, 49, 64, 81]

从数学的角度来看,就是一个映射

x_list = [1,2,3,4,5,6,7,8,9]
y_list = [1, 4, 9, 16, 25, 36, 49, 64, 81]

results matching ""

    No results matching ""