Thursday, June 18, 2009

python: numbers starting with zero are octagonal

I was debugging my script and I found that a number that starts from zero is different that the number without zero. This is because these numbers are octal literals. For example In [1]: a=23
In [2]: b=023
In [3]: a==b
Out[3]: False
In [4]: print a,b
23 19
It appears that when a number starts from zero it is treated as an octagonal number rather than decimal number. Good to know, as it is easy to make mistake.

No comments:

Post a Comment