[Tutor] what is wrong with this syntax?

Steven D'Aprano steve at pearwood.info
Tue May 18 17:23:55 CEST 2010


On Tue, 18 May 2010 11:36:02 pm Dipo Elegbede wrote:
> ples help me figure out what is wrong with this syntax?
>
>
> print('Here are the numbers from 0 to 9')
> for i in the range(10):
>     print(i)
>
> thank you.

Others have already given you the answer, but more important is for you 
to learn *how* to get the answer.

Look at the error message Python prints:

>>> for i in the range(10):
  File "<stdin>", line 1
    for i in the range(10):
                     ^
SyntaxError: invalid syntax


You get a SyntaxError, which tells you that what you've written makes no 
sense to the Python compiler. It also tells you that the error has 
nothing to do with either of the print lines.

Unfortunately Python isn't smart enough to recognise that the problem is 
with "the" rather than "range(10)", but it points you to the correct 
line.



-- 
Steven D'Aprano


More information about the Tutor mailing list