Last active
September 26, 2020 08:12
-
-
Save eclecticmiraclecat/b9e2724220e851f330ef983069de3129 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Upper: | |
... def uppercase(self, value): | |
... print(value.upper()) | |
... | |
>>> u = Upper() | |
>>> u.uppercase('hi') | |
HI | |
>>> class DashUpper(Upper): | |
... def uppercase(self, value): | |
... value = f'--{value}--' | |
... super().uppercase(value) | |
... | |
>>> d = DashUpper() | |
>>> d.uppercase('hi') | |
--HI-- | |
>>> | |
>>> class DashMixin: | |
... def uppercase(self, value): | |
... value = f'--{value}--' | |
... super().uppercase(value) | |
... | |
>>> class DashUpperNew(DashMixin, Upper): | |
... pass | |
... | |
>>> dm = DashUpperNew() | |
>>> dm.uppercase('hi') | |
--HI-- | |
>>> class Name: | |
... def __init__(self, name): | |
... self.name = name | |
... | |
>>> class UpperNameMixin: | |
... def upper(self): | |
... print(self.name.upper()) | |
... | |
>>> class UpperName(UpperNameMixin, Name): | |
... pass | |
... | |
>>> c = UpperName('bob') | |
>>> | |
>>> c.name | |
'bob' | |
>>> c.upper() | |
BOB | |
>>> class UpperName2(UpperNameMixin, Name): | |
... def uppername(self): | |
... print(self.name.upper()) | |
... | |
>>> c = UpperName2('bob') | |
>>> c.upper() | |
BOB | |
>>> c.uppername() | |
BOB | |
>>> class Name2(UpperNameMixin): | |
... def __init__(self, name): | |
... self.name = name | |
... | |
>>> b = Name2('blue') | |
>>> b.upper() | |
BLUE | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment