> Python copies variables' values when passing them to functions > a.. Since Booleans, numbers, and strings can't be updated, a > function can't affect its caller's values > b.. But if you pass a list to a function, the function will operate > on the original list, not a copy > ---------------- > > The first line is plain wrong. Python doesn't copy values it always uses > references, > its just that some objects are immutable while others are mutable. This is a > common cause of confusion for beginners and this statement won't help. And > the last line suggests that Python behaves inconsistently (which it doesn't) > but > doesn't clarify any of the "exceptions" other than lists - the same is > actually > true of any mutable type
i completely agree with alan on this. whoever wrote it does *not* know Python very well. they seem to be "guessing" based on their previous experience with other programming languages that are "categorized" into either "call by reference" or "call by value". in python, *everything* is call by reference, but the reality is that the mutability is the real source of truth. a simple call to id() from the caller and the called function will show that they are indeed the exact same object. (why else would i spend an entire chapter on this in Core Python?!?) getting confused by both of these (call by XX vs. mutability) is the source of many many bugs in Python, and if you can get past this, those bugs would never exist (or have never existed), leaving you in a much more peaceful state of mind. :-) cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor