eval('07') works, eval('08') fails, why?

Mark Dickinson dickinsm at gmail.com
Thu Jan 8 10:38:35 CET 2009

On Jan 8, 9:31 am, Alex van der Spek <am... at xs4all.nl> wrote:

> >>> eval('07')
> 7
> >>> eval('08')
> Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     eval('08')
>   File "<string>", line 1
>     08
>      ^
> SyntaxError: invalid token

An integer literal with a leading zero is
interpreted as an octal (base 8) number,
so only digits in the range 0-7 (inclusive)
are permitted in such a literal.


> I can't think of anything that could cause this. Similarly, eval('09')
> fails, but for string 0x with x<8 it works. I am teaching myself Python
> in order to climb the ladder from Algol(1980s)-->Pascal(1990s)-->VisualBasic(2000)-->Python. I am a physicist, have programmed computers
> all my life but I won't understand the real tech jargon of present day
> computer science. Please keep it simple
> Thanks in advance,
> Alex van der Spek

More information about the Python-list mailing list