Can someone explain to me why the 08s are not orange? Did I write it wrong?
Asked
Active
Viewed 39 times
1
-
4Possible duplicate of [What do numbers starting with 0 mean in python?](https://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python) – Feb 06 '18 at 15:01
-
While I cannot see the image, I think it the 08 might be getting viewed as an octal number. – Arnav Borborah Feb 06 '18 at 15:01
-
2Yup. It also happens with 09, but it doesn't with 02 or any number lower than 8. The leading 0 represents octal numbers. Just try to open the python (python2) console and type `022`. do you expect a 22? Nah, it's 18. Now try 08. Expect an 8? Nah, you will get a `SyntaxError: invalid token` – Feb 06 '18 at 15:04
-
How can I fix this – Feb 06 '18 at 15:04
-
Python doesn't support numeric constants with a leading zero; the only way to fix the problem is to remove the leading zeros from those numbers. Replace them with spaces if you want to keep everything lined up. – OdatNurd Feb 06 '18 at 23:47
-
1Sorry, more specifically Python 3 flat out rejects such a number no matter what; Python 2 will allow it, unless the number isn't valid octal (`08` for example is not). Even so, it's highly unlikely that you mean to have a couple of octal constants in the middle of a bunch of decimal ones, so the correct answer is still to remove the leading zeros. – OdatNurd Feb 07 '18 at 00:24