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:
- Consisting of letters (a-z, A-Z)
- Including digits (0-9) but can’t start with a digit
- Including underscores (
_
) - Being case-sensitive, meaning
OneVariable
,oneVariable
, andONEVARIABLE
are distinct identifiers
You must know that most Python keywords can’t be used as identifiers. 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:
# 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. You have constants, variables, a function, and a class. Each of them serves a different purpose within a Python program.
Related Resources
Tutorial
Variables in Python: Usage and Best Practices
In this tutorial, you'll learn how to use symbolic names called variables to refer to Python objects, and gain an understanding of how to effectively use these fundamental building blocks in your code to store, manipulate, and retrieve data.
For additional information on related topics, take a look at the following resources:
- Python Constants: Improve Your Code's Maintainability (Tutorial)
- Defining Your Own Python Function (Tutorial)
- Python Classes: The Power of Object-Oriented Programming (Tutorial)
- Variables in Python (Course)
- Variables in Python: Usage and Best Practices (Quiz)
- Defining Python Constants for Code Maintainability (Course)
- Defining and Calling Python Functions (Course)
- Defining Your Own Python Function (Quiz)
- Class Concepts: Object-Oriented Programming in Python (Course)
- Inheritance and Internals: Object-Oriented Programming in Python (Course)
- Python Classes - The Power of Object-Oriented Programming (Quiz)
By Leodanis Pozo Ramos • Updated April 16, 2025