为什么sum=0写的顺序不一样,结果还不通??
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])
和
def square_of_sum(L): for x in L: sum = 0 sum = sum + x * x return sum print square_of_sum([1, 2, 3, 4, 5]) print square_of_sum([-5, 0, 5, 15, 25])
结果是不一样的?这个是什么规则?