不太理解print square_of_sum([-5, 0, 5, 15, 25]) 这个为什么不是打印出LIST了?
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])
最后的print里的数列为什么不是打印出来,而是对前面square_of_sum(L)定义了?最后的输出结果是sum的值,可是并没有写print sum,为什么会输出sum值了?感觉对这节里的这两个逻辑不是很清楚。
我分别试验过def square_of_sum(L):
square_of_sum([1, 2, 3, 4, 5])
sum = 0
for x in L:
sum = sum + x*x
return sum
print sum
和
def square_of_sum(L):
square_of_sum([1, 2, 3, 4, 5])
sum = 0
for x in L:
sum = sum + x*x
return sum
print square_of_sum
都无法成功输出结果,不知道我为什么错了