Locked lesson.
About this lesson
What are the built-in Python class attributes?
Exercise files
Download this lesson’s related exercise files.
Built-In Class Attributes.docx59.4 KB Built-In Class Attributes - Solution.docx
60 KB
Quick reference
Built-In Class Attributes
Python classes have some built-in attributes that you can access.
When to use
Use these to access Python's built-in class attributes.
Instructions
There are 4 or 5 built-in attributes you can access. To access these, put a dot after your class name and type in the attribute.
Assuming our class is named Employee:
Employee.__dict__ = dictionary, returns class name space information
Employee.__doc__ = returns documentation (you can put a line of documentation in quotes after you define your class name)
Employee.__name__ = returns the name of your class
Employee.__module__ = prints out module info about your class
Employee.__bases__ = prints out base class info in tuple form
Hints & tips
- .__dict__
- .__doc__
- .__name__
- .__module__
- .__bases__
Lesson notes are only available for subscribers.