Skip to main content
added 121 characters in body
Source Link
Barb
  • 101
  • 1

A sub class will use the attributes of the parent class. You can add more attributes without disturbing the parent class which is useful. Using the super().__init__ method will let you set the attributes from the parent class into the subclass. In example:

class BananaContainer:
    def __init__(self, _bananas):
        self._bananas = _bananas


user1 = BananaContainer(0)
print(user1._bananas)


class AddBananas(BananaContainer):
    def __init__(self):
        super().__init__(_bananas=20)


user2 = AddBananas()
print(user2._bananas)

The output:

0
20

This can be used in a number of ways usually with an input method that will append the variable. To inherit from multiple classes I would use a function that reads them separately initially, then iconfies the result.

A sub class will use the attributes of the parent class. You can add more attributes without disturbing the parent class which is useful. Using the super().__init__ method will let you set the attributes from the parent class into the subclass. In example:

class BananaContainer:
    def __init__(self, _bananas):
        self._bananas = _bananas


user1 = BananaContainer(0)
print(user1._bananas)


class AddBananas(BananaContainer):
    def __init__(self):
        super().__init__(_bananas=20)


user2 = AddBananas()
print(user2._bananas)

The output:

0
20

This can be used in a number of ways usually with an input method that will append the variable

A sub class will use the attributes of the parent class. You can add more attributes without disturbing the parent class which is useful. Using the super().__init__ method will let you set the attributes from the parent class into the subclass. In example:

class BananaContainer:
    def __init__(self, _bananas):
        self._bananas = _bananas


user1 = BananaContainer(0)
print(user1._bananas)


class AddBananas(BananaContainer):
    def __init__(self):
        super().__init__(_bananas=20)


user2 = AddBananas()
print(user2._bananas)

The output:

0
20

This can be used in a number of ways usually with an input method that will append the variable. To inherit from multiple classes I would use a function that reads them separately initially, then iconfies the result.

Source Link
Barb
  • 101
  • 1

A sub class will use the attributes of the parent class. You can add more attributes without disturbing the parent class which is useful. Using the super().__init__ method will let you set the attributes from the parent class into the subclass. In example:

class BananaContainer:
    def __init__(self, _bananas):
        self._bananas = _bananas


user1 = BananaContainer(0)
print(user1._bananas)


class AddBananas(BananaContainer):
    def __init__(self):
        super().__init__(_bananas=20)


user2 = AddBananas()
print(user2._bananas)

The output:

0
20

This can be used in a number of ways usually with an input method that will append the variable