100 days of code: Day 29 - inheritance

Last modified on 2020-07-07

Source: 100-days-of-code.

Today I use inheritance in users.py to create a specialized child class Superuser that takes on the attributes and methods of my parent class User

class User:
    """A simple attempt to represent a user."""

    def __init__(self, first_name, last_name, city, country):
        self.first_name = first_name
        self.last_name = last_name
        self.city = city
        self.country = country
        self.login_attempts = 0
        self.max_login_attempts = 3


class Superuser(User):
    """Represent special privilegs for a system's superuser."""

    def __init__(self, first_name, last_name, city, country):
        """Initialize attributes of the parent class."""
        super().__init__(first_name, last_name, city, country)

Writing the super() function allows me to use all the generic stuff common to all users plus add new methods specific to Superuser.

Happy hacking!