Skip to content

identifier

In Python, an identifier is a name that identifies a variable, function, class, module, or other object. Identifiers are fundamental for writing Python code because they allow you to refer to data and functions in your programs using descriptive names.

Identifiers must follow certain rules to be valid:

  • Consist of ASCII letters a-z and A-Z, or non-ASCII Unicode letters
  • Include digits (0-9) but can’t start with a digit
  • Include underscores (_)
  • Be case-sensitive, meaning OneVariable, oneVariable, and ONEVARIABLE are all different identifiers

Since Python 3, identifiers can also contain non-ASCII Unicode letters, as specified by PEP 3131. For example, café and número are valid identifiers.

Python’s keywords, like if, for, and class, can’t be used as identifiers. The exception is soft keywords such as match and type, which are keywords only in specific contexts and remain valid identifiers elsewhere. It’s important to choose meaningful and descriptive identifiers to make your code more readable and maintainable.

Examples

Here are a few quick examples of using identifiers in Python:

Language: Python
# Constants
PI = 3.142
MAX_SPEED = 300
DEFAULT_COLOR = "\033[1;34m"

# Variables
counter = 10
final_balance = 1_000.00
language = "Python"

# Function
def greet(name):
    return f"Hello, {name}!"

# Class
class Dog:
    def __init__(self, name):
        self.name = name

In these examples, you have several valid identifiers. There are constants, variables, a function, and a class. Each of them serves a different purpose within a Python program.

Variables in Python

Tutorial

Variables in Python: Usage and Best Practices

Explore Python variables from creation to best practices, covering naming conventions, dynamic typing, variable scope, and type hints with examples.

basics python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated July 8, 2026 • Reviewed by Dan Bader