Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Python identifiers—the names used for variables, functions, classes, and other objects—must start with a letter or underscore, may include digits after the first character, and cannot be reserved keywords. Python also accepts many Unicode letters, but normalization and look-alike characters mean that ASCII names are often the clearest choice for shared code. The syntax rules come from the language; conventions such as snake_case come from PEP 8.
What makes a name a valid Python identifier?
The Python 3.14.7 Language Reference defines a name as a starting character followed by zero or more continuation characters. A name must contain at least one character, and the language imposes no maximum length. The reference states: “Names must contain at least one character, but have no upper length limit.” Python Language Reference: Names (identifiers and keywords).
- A name can begin with an ASCII letter (
A–Zora–z) or an underscore (_). - A digit can appear after the first character, but not at the beginning.
- Eligible non-ASCII characters can also be used.
- Names are case-sensitive:
itemandItemare different identifiers.
| Example | Valid? | Reason |
|---|---|---|
count2 |
Yes | A digit appears after the first character. |
_cache |
Yes | An underscore may start a name. |
2count |
No | A name cannot start with a digit. |
item and Item |
Both valid, distinct | Python distinguishes uppercase and lowercase letters. |
Which names are forbidden or context-dependent?
Reserved keywords
Keywords have a defined grammatical role and cannot be used as ordinary identifiers. Examples include class, def, for, if, import, return, and while, as well as True, False, and None. The complete set can vary between Python versions. To inspect the interpreter you are running, use the keyword module:
import keyword
print(keyword.kwlist)
Check the target Python interpreter when code needs to account for its exact keyword set.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Soft keywords
Soft keywords have a special meaning only in particular grammar contexts, so their spellings can still be identifiers elsewhere. The language reference describes match, case, and _ as soft keywords in relevant contexts. For example, _ is a wildcard in a case pattern; that role does not make it a reserved keyword everywhere.
Can Python identifiers contain Unicode?
Yes. Python permits Unicode characters that meet its identifier rules, including letters from many writing systems. The language reference gives ř_1, 蛇, and साँप as valid examples. It also shows that Unicode support does not allow every symbol: r〰2, €, and 🐍 are invalid identifier examples. See the identifier character rules in the Python 3.14.7 Language Reference.
Rank #2
Normalization can make different spellings equivalent
Python normalizes identifiers to NFKC while parsing. As a result, two character sequences that normalize to the same form can denote the same name. A typographic spelling is not necessarily a distinct identifier just because it looks different on screen. The behavior is specified in the Language Reference and explained in PEP 3131.
Look-alike characters can confuse readers
Some letters from Latin, Greek, and Cyrillic scripts look alike while remaining different characters and distinct identifiers. PEP 672 discusses these Unicode confusables and their security implications: PEP 672: Unicode-related security considerations. This is a reason to review unfamiliar names carefully, not a reason to treat every Unicode identifier as unsafe. In a multilingual codebase, agree on consistent script use and choose names that teammates can reliably recognize.
What naming style should you use?
Syntax determines what Python accepts; style helps people understand the code. PEP 8 recommends these conventions:
| Name’s role | PEP 8 convention | Example |
|---|---|---|
| Variable or function | Lowercase words separated by underscores (snake_case) |
item_count, load_record() |
| Class | Capitalized words joined together (CapWords) |
CustomerRecord |
| Constant | Uppercase words separated by underscores | MAX_RETRIES |
| Module | Generally short and lowercase; underscores may improve readability | data_tools |
These are conventions, not parser requirements. PEP 8 says that “Names that are visible to the user as public parts of the API should follow conventions that reflect usage rather than implementation.” Read more in PEP 8: Naming Conventions.
Handle awkward names without making them cryptic
- If an argument would conflict with a keyword, PEP 8 recommends adding one trailing underscore, such as
class_, rather than abbreviating or distorting the word. - Avoid single-character lowercase
l, uppercaseO, and uppercaseIwhen a font could make them look like digits. - For public names, prioritize how callers use and understand the API over the details of its implementation.
How to choose between two possible names
When both candidates look plausible, evaluate them in this order:
Quick Recap
Best Value
- Check the grammar: does the name start with an allowed character and use only allowed continuation characters?
- Check for a keyword conflict: is it reserved in the Python version the code targets?
- Match the role: use the PEP 8 convention for a variable, function, class, constant, or module.
- Read it at the call site: choose the spelling that makes the code’s purpose clear to its intended readers.
- Consider Unicode effects: avoid relying on normalization differences or visually confusable characters to distinguish names.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




