How does python interpret numbers with leading zeroes

If a number starts with 0, it is interpreted as octal, or base 8. Just do:

print 1
print 10
print 100
print 1000

And your problem will be solved.

More on octal: http://en.wikipedia.org/wiki/Octal

Here is a way to understand octal easier:

octal 1 is decimal (normal numbers) 1

octal 2 : decimal 2

octal 7 : decimal 7

octal 10: decimal 8

octal 11: decimal 9

octal 12: decimal 10

octal 17: decimal 15

octal 20: decimal 16

and so on. Octal just uses digits from 0 to 7.

Hope this helped!

Leave a Comment