1
$ python -V
Python 2.7.10

$ uname -a
Darwin Carters-MacBook-Pro-2.local 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64

I was trying to do something like this today in the python interpreter

datetime.datetime(2019, 07, 26) - datetime.datetime.today()

and this worked fine, but when I went to

datetime.datetime(2019, 08, 26) - datetime.datetime.today()

it throws a "SyntaxError: invalid token"

Then I tried this

>>> 01
1
>>> 02
2
>>> 03
3
>>> 04
4
>>> 05
5
>>> 06
6
>>> 07
7
>>> 08
  File "<stdin>", line 1
    08
     ^
SyntaxError: invalid token

what's going on?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
John Allard
  • 3,564
  • 5
  • 23
  • 42

1 Answers1

1

This is because in python 2 leading zeros denotes that the number is an octal number so as in octal we don't have 8 it goves this error.

Note: Python3 doesn't allow leading zeros

Ankit Agrawal
  • 616
  • 9
  • 20