Built In Class Attributes

Every Python class automatically comes with a set of built-in attributes that provide useful information about the class itself, without you needing to define them manually.

Common Built-In Class Attributes

  • __dict__ - a dictionary containing the class's namespace, including its attributes and methods
  • __doc__ - the class's docstring, if one has been written
  • __name__ - the name of the class as a string
  • __module__ - the name of the module in which the class was defined
  • __bases__ - a tuple containing the class's parent (base) classes
class Student:
    """Represents a student enrolled in a course."""
    def __init__(self, name):
        self.name = name

print(Student.__name__)    # Student
print(Student.__doc__)     # Represents a student enrolled in a course.
print(Student.__module__)  # __main__
These built-in attributes are especially useful for debugging, introspection, and writing generic code that needs to inspect classes without knowing their exact structure in advance.

Coming Up Next

Next, you'll learn how Python controls access to class attributes and methods through public, protected, and private conventions.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course