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:/
On 2021-09-20, ast wrote:
> 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 und
En Wed, 13 Jun 2007 03:01:16 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
escribió:
> I'm writing a program and want to create a class that is derived from
> the "str" base type. When I do so, however, I have problems with the
> __init__ method. When I run the code below, it will call my new
>
I'm writing a program and want to create a class that is derived from
the "str" base type. When I do so, however, I have problems with the
__init__ method. When I run the code below, it will call my new
__init__ method when there is zero or one (value) parameter. However,
if I try to pass two pa