attribute
A named value attached to an object and reached with a dot, such as point.x or math.pi; methods are attributes too.
In more detail
Instance attributes are usually set in __init__ through self; class attributes are set in the class body and shared by all instances. Asking for one that does not exist raises AttributeError.
Related terms
- instance attribute — An attribute stored on one instance, usually set as self.name = value, so each instance has its own copy.
- class attribute — An attribute defined in the class body, shared by every instance of the class.
- dot notation — Writing object.name to reach a method or attribute that belongs to an object or module, as in s.upper() or math.pi.
- AttributeError — The exception raised when code asks an object for a method or attribute it does not have.
Taught in
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book
- HTML Forms And Dynamic Programs — Hands-on Python: Complete Video Course & Book
- Classes And Instances — Hands-on Python: Complete Video Course & Book
- Methods, Attributes And self — Hands-on Python: Complete Video Course & Book