python admin abuse complaint

Jonathan Gardner jgardner at jonathangardner.net
Tue Feb 2 22:35:50 CET 2010


On Feb 2, 12:40 pm, Xah Lee <xah... at gmail.com> wrote:
>
> (12:12:16 PM) xahlee: is hash={} and hash.clean() identical?
>

I think you mean hash.clear() instead of hash.clean()

The answer is that "hash = {}" will create a new dict and assign it to
"hash", while "hash.clear()" simply guts the dict that "hash" is
pointing to.

In the end, both will result in "has" pointing to an empty dict.

However, if you had something else pointing to what "hash" was
pointing to, they will no longer be pointing to the same, empty hash
after "hash = {}" is run.

>>> a = b = {1:2}
>>> a
{1: 2}
>>> b
{1: 2}
>>> a.clear()
>>> a
{}
>>> b
{}
>>> a = b = {1:2}
>>> a = {}
>>> a
{}
>>> b
{1: 2}



More information about the Python-list mailing list