也许是这个?
# Use this import for all examples
from math import sqrt
old = [1,2]
new = [sqrt(x) for x in old]
函数形式
def sqrt_list(old):
return [sqrt(x) for x in old]
或
def sqrt_list(old):
new_list = []
for i in old:
new_list.append(sqrt(i))
return new_list
哪里:
print(sqrt_list([11, 22, 33]))
产出:
[3.3166247903554, 4.69041575982343, 5.744562646538029]