python variable assignement

Carsten Haese carsten at uniqsys.com
Mon Sep 24 08:31:53 EDT 2007


On Mon, 2007-09-24 at 12:12 +0000, mihai wrote:
> [...]
>         id = add(record)
> [...]

Not that this causes your problem, but I'd still like to point out that
'id' is the name of a built-in function. Shadowing built-in names can
lead to surprising behavior.

> Is there a way to see if the names points to the same variables or
> that there are different variables with the same values?

Yes. "==" tests whether two objects are equal, whereas "is" tests
whether two objects are actually the same object. Examples:

Two different list objects with equal contents:

>>> a = [1,2,3]
>>> b = [1,2,3]
>>> a==b
True
>>> a is b
False

Two names for the same list object:

>>> a = [1,2,3]
>>> b = a
>>> a==b
True
>>> a is b
True

Hope this helps,

-- 
Carsten Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list