boB Stepp <robertvst...@gmail.com> writes: > >>> 01 > File "<stdin>", line 1 > 01 > ^ > SyntaxError: invalid token
As you later explain, this is because in Python 3 the obsolete “leading 0 for octal notation” is invalid syntax. (Superseded by “leading ‘0o’ for octal notation”). > >>> 00 > 0 > >>> -00 > 0 > >>> 000 > 0 > > Why do zeros not give a syntax error, but other numbers with a leading > zero do give a syntax error? Hmm. That is a confusing inconsistency, I agree. It is deliberate, and explicitly documented: Note that leading zeros in a non-zero decimal number are not allowed. This is for disambiguation with C-style octal literals, which Python used before version 3.0. <URL:https://docs.python.org/3/reference/lexical_analysis.html#integer-literals> which does not explain why “non-zero decimal number” was chosen, rather than simply any decimal number. > But then why is 00...0 valid, that is, does not give a syntax error? At one level, the answer is: because the language reference declares those rules for the syntax. At another level, the answer is: I don't know why that decision was made, and on the face of it I disagree. -- \ “But it is permissible to make a judgment after you have | `\ examined the evidence. In some circles it is even encouraged.” | _o__) —Carl Sagan, _The Burden of Skepticism_, 1987 | Ben Finney _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor