newbie: confused with example in Learning Python 2nd Edition:cananyone give a hint

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Aug 23 21:54:57 EDT 2004


"Robert Brewer" <fumanchu at amor.org> wrote in message
news:mailman.2254.1093312305.5135.python-list at python.org...
Porky Pig Jr wrote:
<snip>

Hint: Python doesn't have variables like other languages do. The line:

    self._data = list(data)

does not make a copy of "data". Instead, it binds a new name
(self._data) to the same object which the name "data" refers to.


FuManChu
======================

Er?  I thought list(data) called the list constructor to create a copy of
data, and bind the new list to self._data.  That's why push and pop calls
update the internal _data list without changing the original list.

-- Paul





More information about the Python-list mailing list