0

I found, this in Python3:

>>> 00 + 00 == 00
True

While:

>>> 01 + 01 == 02
    File "<input>", line 1
01 + 01 == 02
 ^
SyntaxError: invalid token

Why does the first example works while the second one fails? Should't it be better if both failed or both worked?

juan Isaza
  • 3,646
  • 3
  • 31
  • 37
  • because you can input integers in `oct` or `hex` using leading zero, for example `0o71` == `0x39`, so `01` - its in octal/decimal/hex form? I don't know, `explicit is better than implicit`. – sKwa Aug 27 '17 at 02:17

1 Answers1

4

From Integer literals:

Note that leading zeros in a non-zero decimal number are not allowed. This is for disambiguation with C-style octal literals, which Python used before version 3.0.

You can read the lexical definitions to understand the rule to parse integer literals.