3

When I type

datetime.date(2104,06,08)

or

datetime.date(2014,06,09)

I get an error

File "<stdin>", line 1
 datetime.date(2014,06,08)
                       ^
SyntaxError: invalid token

But when I remove the zero in '08' or '09' it works. The problem seems to be only with 8 and 9 and not with any other numbers. If anyone knows a work around, it would be great

da4kc0m3dy
  • 132
  • 1
  • 10
  • http://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python – Sam Jun 13 '14 at 07:45
  • https://docs.python.org/2/faq/programming.html#how-do-i-specify-hexadecimal-and-octal-integers – Sam Jun 13 '14 at 07:47

3 Answers3

5

A number literal starting with 0 is interpreted as octal (base 8). 8 and 9 aren't octal digits.

Just don't use leading zeros.

user2357112
  • 260,549
  • 28
  • 431
  • 505
1

This is because a leading zero is octal notation.

But in octal notation there do not exist such expressions as 08 or 09.

Roberto Reale
  • 4,247
  • 1
  • 17
  • 21
1

Adding a 0 in front of a number makes it base 8, there are no 08 or 09 in base 8 only (well, not only, but for single digits):

00
01
02
03
04
05
06
07

Avoid using the zero out in front and you should be ok.

Dair
  • 15,910
  • 9
  • 62
  • 107