Defining a function name that starts with a number (in Python 3)?

I tried to create the following function: def 3utr(): do_something(). However, I get a SyntaxError. Replacing β€œ3” with β€œthree” fixes the problem.

My questions:

  • Why is this a syntax error?
  • Is there a way for a function name to start with a number in Python 3?
+3
source share
1 answer

This is a syntax error because the language specification does not allow identifiers to begin with a digit. Thus, it is not possible to have function names (which are identifiers) that start with numbers in Python.

identifier ::= (letter|"_") (letter | digit | "_")*

Python 2 Reference

ASCII (U + 0001..U + 007F) , Python 2.x: A Z, _ , 0 9.

Python 3

+7

All Articles