2

Actually I am beginner in Python. I just want to know why python gives error on print of integer which is starting with 0 (non single digit)

for e.g. if I type 09 in integer then on printing it gives error

SyntaxError: invalid token
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
J.Smith.JJJ
  • 199
  • 2
  • 2
  • 9
  • Because Python thinks you are creating an octal number; in Python 3 that's always an error, in Python 2 octal numbers like 07 do work. – Martijn Pieters Sep 05 '14 at 13:22

1 Answers1

2

0 at the beginning of a numeric literal is used to tell python which base to use, for example: 0x12.

Using 09 you are expressing 9 in octal base but 9 is not a valid digit in that base and thus the error.