Why Python don't accept 03 as a number?

MRAB python at mrabarnett.plus.com
Fri Dec 7 23:17:09 EST 2018


On 2018-12-08 03:49, Joe Pfeiffer wrote:
> jfong at ms4.hinet.net writes:
> 
>> MRAB at 2018/12/8 UTC+8 AM10:04:51 wrote:
>>> Before Python 3, a leading 0 in an integer literal would indicate an 
>>> octal (base 8) number.
>>
>> So, the reason is historical.
>>
>>> The old form is now invalid in order to reduce the chance of bugs.
>>
>> I encounter this problem on trying to do something like this:
>>     eval('03 + 00 + 15')
>> It takes me some efforts to get rid of those leading zeros:-(
>>
>> Hope someday 03 can be accepted as a valid decimal number in Python 3.
>>
>> Thank you for explaining.
>>
>> --Jach
> 
> I'd say we *really* don't want that.  We'd have old C programmers (like
> me) expecting 010 to mean 8, and getting really confused...
> 
We could just wait until all the old C programmers have died. :-)



More information about the Python-list mailing list