leading zeros in python

python, python-2.7, syntax-error

Solution

Numbers with a leading zero in them are interpreted as octal, where the digits `8` and `9` don't exist.

It's worse in Python 3, leading zeros are a syntax error no matter which digits you use. See What’s New In Python 3.0 under "New octal literals". Also PEP 3127.

Problem

Python seems to be able to accept leading zeros for any number except 08 or 09. For instance, ``` a = 04 ``` works in the interpreter but ``` a = 08 ``` returns ``` SyntaxError: invalid token ``` I'm using python 2.7.3 on OSX, and others have been able to duplicate the error. What gives?

Original source

Related problems