simultaneous assignment

bruno at modulix onurb at xiludom.gro
Tue May 2 13:50:54 EDT 2006


John Salerno wrote:
> Is there a way to assign multiple variables to the same value,
> but so
> that an identity test still evaluates to False?

re-phrase it according to how Python works, and you'll get the answer:

"Is there a way to bind multiple names to the same object, but so the
identity of this object is different from the identity of this object ?"

> e.g.:
> 
>>>> w = x = y = z = False

the statement:
  a = False
doesn't mean "assign the value False to the variable a", but "make the
name 'a' reference the object False" - which is quite different.

>>> a = False
>>> b = False
>>> a is b
True
>>> id(False)
46912499309888
>>> id(a)
46912499309888
>>> id(b)
46912499309888
>>>


>>>> w
> False
>>>> x
> False
>>>> w == x
> True
>>>> w is x
> True         # not sure if this is harmful

Using identity test for boolean tests is usually not a good idea since
many other objects evals to True or False in a boolean context while not
being neither the True nor the False objects.

> The first line above is the only way I know to do it, but it seems to
> necessarily lead to the true identity test.

It does.

Now if I may ask: what is your actual problem ?

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list