Created
September 14, 2021 09:21
-
-
Save Tishka17/8d5f0ef0ac42c7bf7e3959458dace9f3 to your computer and use it in GitHub Desktop.
Incorrect str inheritance
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 MyString(str): | |
def __init__(self, data): | |
self.data = data | |
def append(self, other): | |
self.data += other | |
def __str__(self): | |
return self.data | |
a = MyString("hello") | |
print(a) | |
print(a + " world") | |
a.append(" world") | |
print(a) | |
print(a + " again") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment