Attribute
In one line
An attribute is a named value stored on an object, accessed with dot notation (obj.attribute).
In simple words
An attribute is a piece of data stored on an object. You access it with dot notation: obj.attribute. Attributes are typically set in __init__ using self.name = value.
There are two kinds of attributes: instance attributes (unique to each object, set with self) and class attributes (shared by all instances, set on the class itself). Instance attributes are more common.
You can add, modify, or delete attributes at any time using dot notation. Python objects are flexible — you can even add attributes that weren't defined in __init__. Use hasattr(obj, 'name') to check if an attribute exists, and getattr(obj, 'name', default) for safe access.
Example
class Person:
species = "Homo sapiens" # class attribute
def __init__(self, name):
self.name = name # instance attribute
p = Person("Alice")
print(p.name) # Alice (instance attribute)
print(p.species) # Homo sapiens (class attribute)
p.age = 30 # dynamically added attribute
print(p.age) # 30Attributes are object data accessed with dot notation. Instance attributes are per-object; class attributes are shared.
Common confusions
Confused with: method
The difference: An attribute is a data value stored on an object (obj.name). A method is a function stored on an object (obj.method()). Attributes are accessed without parentheses; methods are called with parentheses.
Related terms
Related Resources
Related Lessons
- Classes and Objects
Attributes in Python.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.