Attributes: storing data
Attributes are variables that belong to an object. There are two types: Instance attributes (unique to each object):Methods: adding behavior
Methods are functions that belong to a class. They always haveself as the first parameter, but you don’t pass it when calling:
When you call a method like
validator.validate_email("[email protected]"), Python automatically passes the validator object as self. You only provide the other arguments.Common mistakes
Modifying mutable class attributes
Modifying mutable class attributes
Not initializing attributes
Not initializing attributes
What’s next?
Let’s explore inheritance - how classes can build on other classes.Inheritance
Build on existing classes