Are there any other allowed characters in Python function names except alphabetical characters, numbers, and underscores? If yes, what are they?
Asked
Active
Viewed 1.6k times
17
-
google it: http://www.pasteur.fr/formation/infobio/python/ch02s03.html – BartoszKP Oct 20 '13 at 20:55
-
possible duplicate of [Valid characters in a python class name](http://stackoverflow.com/questions/10120295/valid-characters-in-a-python-class-name) – Ben Oct 20 '13 at 20:55
-
possible duplicate of [What is the naming convention in Python for variable and function names?](http://stackoverflow.com/questions/159720/what-is-the-naming-convention-in-python-for-variable-and-function-names) – ThreeCheeseHigh Oct 20 '13 at 20:55
-
5@danny Conventional != allowed. – Oct 20 '13 at 20:57
-
1@delnan you are right. – ThreeCheeseHigh Oct 31 '13 at 13:11
1 Answers
16
In Python 3 many characters are allowed:
identifier ::= xid_start xid_continue*
id_start ::= <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl,
the underscore, and characters with the Other_ID_Start property>
id_continue ::= <all characters in id_start, plus characters in the categories
Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>
xid_start ::= <all characters in id_start whose NFKC normalization
is in "id_start xid_continue*">
xid_continue ::= <all characters in id_continue whose NFKC normalization
is in "id_continue*">
The Unicode category codes mentioned above stand for:
Lu - uppercase letters
Ll - lowercase letters
Lt - titlecase letters
Lm - modifier letters
Lo - other letters
Nl - letter numbers
Mn - nonspacing marks
Mc - spacing combining marks
Nd - decimal numbers
Pc - connector punctuations
Other_ID_Start - explicit list of characters in PropList.txt
to support backwards compatibility
Other_ID_Continue - likewise
The complete list of every character can be found on Unicode.org.
In Python 2.x it was limited to just letters, numbers, and underscore. From the docs:
identifier ::= (letter|"_") (letter | digit | "_")*
letter ::= lowercase | uppercase
lowercase ::= "a"..."z"
uppercase ::= "A"..."Z"
digit ::= "0"..."9"

Matt S
- 14,976
- 6
- 57
- 76
-
3Point to any version of the Python 3.x docs, and the answer is yes :) eg: http://docs.python.org/3.2/reference/lexical_analysis.html#identifiers – Jon Clements Oct 20 '13 at 20:55
-