Why Can't I Store a Number Starting with 0?


#1

Why can I not store a number starting with 0?

If I do:

1 todays_date = 06102018

I receive Syntax Error: invalid token

However, there will be no error if I start a number with a non-zero number. Why is this?


What can I store in a variable?
#2

Hi @alamgirkzs,

It’s not possible to store an integer with a leading 0 in Python. Depending on what you want to do, you might be able to store it as a string instead, but the best thing is probably to just add the leading 0 when you print the variable, like this:

todays_date = 6102018

print('{:08d}'.format(todays_date))

#3

Most things you can possibly type are disallowed, or rather, lack meaning. The big question is what you were hoping to get out of it

In python2 it’s valid, but does something non-obvious.


#4
DEC 25 == OCT 31

for curiosity sake.

Christmas and Hallowe’en on the same day seems a little weird.


#5

This topic is solved.