This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Syntax Error on leading 0 in integer tokens
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: jackb, steven.daprano
Priority: normal Keywords:

Created on 2018-04-18 01:11 by jackb, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg315429 - (view) Author: (jackb) Date: 2018-04-18 01:11
Entering 007 gives a syntax error. Should return 7.
00 correctly returns 0.
007. correctly returns 7.0.
msg315430 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-04-18 01:25
This is not a bug, it is intentional.

In Python 2, numbers with a leading zero are interpreted as octal, leading to surprising results:

py> 015
13

In Python 3, we use 0o15 to get octal, and 015 becomes a syntax error.
msg315432 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-04-18 01:48
I've opened an issue to improve the error message: #33305
History
Date User Action Args
2022-04-11 14:58:59adminsetgithub: 77485
2018-04-18 01:48:19steven.dapranosetmessages: + msg315432
2018-04-18 01:25:39steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg315430

resolution: not a bug
stage: resolved
2018-04-18 01:11:07jackbcreate