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

Robert Brewer fumanchu at amor.org
Mon Aug 23 23:02:08 EDT 2004


D'oh! That'll teach me to read too quickly. <:)

> -----Original Message-----
> From: python-list-bounces+fumanchu=amor.org at python.org 
> [mailto:python-list-bounces+fumanchu=amor.org at python.org] On 
> Behalf Of Paul Rubin
> Sent: Monday, August 23, 2004 6:58 PM
> To: python-list at python.org
> Subject: Re: newbie: confused with example in Learning Python 
> 2nd Edition:cananyone give a hint
> 
> 
> "Robert Brewer" <fumanchu at amor.org> writes:
> > > So: why defitions of self.push and self.pop are defined as
> > > 'data.append' rather than '_data.append', etc.
> 
> It's an error.  It should say _data.append.
> 
> > 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.
> 
> The list function does make a copy.
> 
>     Python 2.3.4 (#1, Jul 24 2004, 19:45:58)
>     [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
>     Type "help", "copyright", "credits" or "license" for more 
> information.
>     >>> j=[9,8]
>     >>> a=list(j)
>     >>> a is j
>     False
>     >>> j.append(2)
>     >>> j
>     [9, 8, 2]
>     >>> a
>     [9, 8]
>     >>>
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list