guys, I'm learning Python recently, I got a problem when I write some simple codes in Python Shell(command in Terminal in Linux) and in a file:
in Python Shell:
>>> def firstn(n):
... num, nums = 0, []
... while num < n:
... nums.append(nums)
... num += 1
... return nums
... sum_of_first_n = sum(firstn(1000000))
File "<stdin>", Line7
sum_of_firstn_n = sum(firstn(1000000))
^
SyntaxError: invalid syntax
if print(sum(firstn(1000000))), the print will be a SyntaxError too
But when I put the codes into a file, and execute it, it is totally OK, no SyntaxError, I don't know why. Is there anyone who can explain this? PS: The code is from https://wiki.python.org/moin/Generators