Mailing List Archive

Inheriting from str
Hello

class NewStr(str):
def __init__(self, s):
self.l = len(s)

Normaly str is an immutable type so it can't be modified
after creation with __new__

But the previous code is working well

obj = NewStr("qwerty")
obj.l
6

I don't understand why it's working ?


(python 3.9)
--
https://mail.python.org/mailman/listinfo/python-list