Python cannot handle numbers string starting with 0. Why? -


i executed following program on python interpreter:

>>> def mylife(x): ...     if x>0: ...             print(x) ...     else: ...             print(-x) ...  >>> mylife(01) file "<stdin>", line 1 mylife(01)         ^ syntaxerror: invalid token >>> mylife(1) 1 >>> mylife(-1) 1 >>> mylife(0) 0 

now, have seen this link says, 0 octal not work more in python (i.e. not work in python3). not mean the behaviour numbers starting 0 should interpreted properly? either in base-2 or in normal base-10 representation? since not so, why python behave that? implementation issue? or semantic issue?

my guess since 012 no longer octal literal constant in python3.x, disallowed 012 syntax avoid strange backward compatibility bugs. consider python2.x script using octal literal constants:

a = 012 + 013 

then port python 3 , still works -- gives a = 25 instead of a = 21 expected (decimal). have fun tracking down bug.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -