On 8/6/20 10:53 PM, ZHAOWANCHENG wrote:
> So instances of user-defined classes are immutable by default?
> Or the description of "if a tuple contains any mutable object either
> directly or indirectly, it cannot be used as a key." in the document
> is not completely correct?
> The description menti
On 8/6/20 8:53 PM, ZHAOWANCHENG wrote:
> So instances of user-defined classes are immutable by default?
No, they're clealry mutable.
> Or the description of "if a tuple contains any mutable object either directly
> or indirectly, it cannot be used as a key." in the document is not
> completel
me = mycls()
>>> >>> me.a = 2 # mutable?
>>> >>> {(1, me): 'mycls'}
>>> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'}
>>> >>>
>>>
>>>
>>> So are
aced into a tuple that as a key of a dict:
> >>> class mycls(object):
> ... a = 1
> ...
> >>> me = mycls()
> >>> me.a = 2 # mutable?
> >>> {(1, me): 'mycls'}
> {(1, <__main__.mycls object at 0x000
): 'mycls'}
>> {(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'}
>> >>>
>>
>>
>> So are instances of user-defined classes mutable or immutable?
>>
> user class instances are clearly mutable, and in my python
On 8/6/20 7:40 AM, Robin Becker wrote:
On 06/08/2020 05:17, ZHAOWANCHENG wrote:
So are instances of user-defined classes mutable or immutable?
user class instances are clearly mutable, and in my python 3.8 you can
do horrid things like this
>
> [snip buggy/incorrect uses of __hash__
hat as a key of a dict:
> >>> class mycls(object):
> ... a = 1
> ...
> >>> me = mycls()
> >>> me.a = 2 # mutable?
> >>> {(1, me): 'mycls'}
> {(1, <__main__.mycls object at 0x022824DAD668>):
of a dict:
>>> class mycls(object):
... a = 1
...
>>> me = mycls()
>>> me.a = 2 # mutable?
>>> {(1, me): 'mycls'}
{(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'}
>>>
So are i
:
... a = 1
...
>>> me = mycls()
>>> me.a = 2 # mutable?
>>> {(1, me): 'mycls'}
{(1, <__main__.mycls object at 0x022824DAD668>): 'mycls'}
>>>
So are instances of user-defined classes mutable or immutable?
--
https://mail.python.org/mailman/listinfo/python-list