Counterintuitive Python behavior

Dave Kuhlman dkuhlman at rexx.com
Mon Apr 22 12:55:19 EDT 2002


Others have given better explanations than I can. But, you might
also look at the 'is' operator and the built-in function id().

    a is b if and only if id(a) == id(b)

The id() function will tell you whether you are dealing with a
reference to the same object or with a copy of the object.

dominikush at yahoo.com wrote:
> 
> Hello,
> 
> one thing I like very much about Python is that statements
> work like you would expect them to work. Take for example
> the use of dict.values() for dictionaries: If you store the
> result of dict.values(), and change the dictionary after-
> wards, the previously stored result remains untouched.


[snip]

-- 
Dave Kuhlman
dkuhlman at rexx.com
http://www.rexx.com/~dkuhlman



More information about the Python-list mailing list