I am trying to enter numbers with input statement, everything is fine, the only problem is when i start the numbers with ‘0’. It gives wrong result. Can someone explain me what exactly happens and why it gives wrong result.
Here is a small example:
>>> a = input("> ")
> 12345
>>> a
12345
>>> a = input("> ")
> 012345
>>> a
5349
>>> print a
5349
>>> if a == 012345: print "matched"
matched
I am not understanding this. Thanks for any help! (Windows XP, Python 2.7.3)
In python 2, starting a number with
0marks it as octal (base 8).12345 oct = 5349 dec