On Fri, 06 Jan 2006 12:01:09 +1100 "Steven D'Aprano" <[EMAIL PROTECTED]> wrote:
> On Wed, 04 Jan 2006 22:51:03 -0500, Mike Meyer wrote: > > >> And if you only ever passed immutable objects around, > >you would > think Python was call by value. > > > > You might. Then again, you might also understand the > > concepts well enough to realize that there isn't any > > difference between CBR and CBV when you're passing > > immutable objects. > > Consider this: > > def do_nothing(x): > pass > > huge_tuple = (None,) * 10000**4 > do_nothing(huge_tuple) > > If Python made a copy of huge_tuple before passing it to > the function, you would notice. Which succinctly demonstrates precisely why a newbie *should* be told that Python passes references instead of values. Without this basic knowledge, the newcomer can't possibly be expected to make intelligent choices of algorithm. But it should probably also be made clear that "reference" means a label assigned to an object, and not a variable containing a memory location (which is what a C "pointer" is). The reference is usually a simple name, but it can also be an container expression following list, dictionary, or class instance (spam, spam[0], spam['eggs'], or spam.ham, for example). Not tuple or string because they are immutable, and so don't have assignable references. Cheers, Terry -- Terry Hancock ([EMAIL PROTECTED]) Anansi Spaceworks http://www.AnansiSpaceworks.com -- http://mail.python.org/mailman/listinfo/python-list