为什么会产生这样的结果
def square_of_sum(L):
sum=0
for x in L:
sum=x*x+sum
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
把return sum放在for x in L的条件里,也能正常运行,结果却是1和25,为什么会产生这样的结果呢
def square_of_sum(L):
sum=0
for x in L:
sum=x*x+sum
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
把return sum放在for x in L的条件里,也能正常运行,结果却是1和25,为什么会产生这样的结果呢
2020-08-14
举报