I'm trying to start a for loop after doing something else in python interpreter on the same line, and it throws a SyntaxError when I do so.
>>> a,b = 0, 1;\
... for i in range(1, 10):
File "<stdin>", line 2
for i in range(1, 10):
^
SyntaxError: invalid syntax
Of course I could just execute them separately here, but if I want to have this inside a function definition then I can't exactly do that. What is the correct syntax to do it in the interpreter?
When you have a backslash, you are telling it to ignore the new line. So Python thought your code was
a,b = 0, 1 for i in range(1,10):
. This is clearly invalid syntax. So, you must remove the semicolon and the backslash. When you want to go to the new line, useshift + enter key
.After that, it should work: