3 ms·
Interestingly, why do they specify base 10 integers as: nonzerodigit (["_"] digit)* | "0" (["_"] "0")* Isn't digit (["_"] "0")* simpler?
by omegalulw 5y ago
Interestingly, why do they specify base 10 integers as: nonzerodigit (["_"] digit)* | "0" (["_"] "0")*
Isn't digit (["_"] "0")* simpler?
- Jasper_ 5y ago012345 is the old way of doing octal notation in Python, which has its roots in C. I'm guessing they want to prevent ambiguity by making it so that it's an error for "012345" to be a decimal literal.
- dr_zoidberg 5y agoYes, it gives an error -- if you want decimals, you can't use leading 0's: Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: 01 File "<ipython-input-1-3351d58b1d3b>", line 1 01 ^ SyntaxError: invalid token In [2]: 0o1 Out[2]: 1 In [3]: 0o10 Out[3]: 8
- nicoburns 5y agoNot only that, octal notation is actually valid in non strict-mode versions of JavaScript (which is still the default unless you opt-in with "use strict"). So it would be backwards incompatible outside of strict mode, and very confusing if changing from non-strict to strict-mode changed the semantics without giving an error/warning.
- tdeck 5y agoI always thought this was one of the worst notation conventions in modern languages.
- Gibbon1 5y agoI've felt for 35 years they could do everyone a favor and break everything that dependens on a leading zero to represent octal.