attribute

An attribute in Python is a value associated with an object that can be accessed using dot notation (object.attribute). Attributes are defining characteristics or properties of an object and can be data attributes (variables) or method attributes (functions).

Python Syntax
class Person:
    species = "human"  # Class attribute

    def __init__(self, name):
        self.name = name  # Instance attribute

Attributes can be:

  • Built-in (like list.append())
  • Instance-specific (created in .__init__())
  • Class-level (shared by all instances)
  • Dynamic (added at runtime)

You can check if an object has an attribute using hasattr(), get attribute values with getattr(), set them with setattr(), and delete them with delattr(). Python’s descriptor protocol allows for fine-grained control over attribute access and modification.

Tutorial

Object-Oriented Programming (OOP) in Python

In this tutorial, you'll learn all about object-oriented programming (OOP) in Python. You'll learn the basics of the OOP paradigm and cover concepts like classes and inheritance. You'll also see how to instantiate an object from a class.

intermediate python

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


By Dan Bader • Updated Jan. 21, 2025