python的平方和怎么理解?
def square_of_sum(L): return sum([i * i for i in L]) print square_of_sum([1, 2, 3, 4, 5]) print square_of_sum([-5, 0, 5, 15, 25]) #def square_of_sum(L): sum = 0 for x in L: sum = sum + x * x return sum print square_of_sum([1, 2, 3, 4, 5]) print square_of_sum([-5, 0, 5, 15, 25])
能帮我理解一下这为什么可以使元素平方和return sum([i * i for i in L])#这个完全不能理解为什么
sum = 0
for x in L:#这个循环的for是使list的元素全计算吧
sum = sum + x * x#这个好理解python的平方并不是反v而是*但是sum+x*x的sum是什么?我记得是使打印的时候是整数?
return sum