Python variables can use a wide range of Unicode characters beyond the ASCII range. Here's a brief overview:
- Latin letters in lower and upper case with diacritics, like "á" or "Ä".
- Greek letters, both lower and upper case, like "α" or "Ω".
- Cyrillic letters, both lower and upper case, like "а" or "Я".
- Other scripts like Arabic, Hebrew, Chinese, Japanese, etc.
- Certain special characters like mathematical symbols, emoji, etc.
Here are a few key rules:
- The first character of a variable name cannot be a digit. It can be an underscore or a letter.
- Apart from the first character, variable names can also include digits.
- Whitespace and certain special characters like "#", "!", "*", "(", ")", "-", "+", "=", "{", "}", "[", "]", ":", ";", "'", "<", ">", ",", ".", "?", "/", "|", "", and "&" are not allowed.
Remember that while Python allows a very wide range of characters in variable names, it's generally best to stick to ASCII letters, digits, and underscores for maximum readability and compatibility.
Here is an official excerpt from Python's documentation:
"Identifiers (also referred to as names) are described by the following lexical definitions:
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 characters with the Other_ID_Continue property>
xid_start ::= <all characters in id_start, plus characters with the XID_Start property>
xid_continue ::= <all characters in id_continue, plus characters with the XID_Continue property>
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 to be allowed as the first character
Other_ID_Continue - explicit list of characters to be allowed in identifiers
XID_Start and XID_Continue - corrections to the Unicode algorithm"