Gabriel Genellina wrote: > En Thu, 12 Jul 2007 21:51:08 -0300, Chris Carlen > <[EMAIL PROTECTED]> escribió: >> http://hetland.org/writing/instant-python.html >> I don't understand Hetland's terminology though, when he is speaking of >> "binding" and "reference." Actually, Hetland's entire first paragraph >> is unclear. > First, see this short article http://effbot.org/zone/python-objects.htm
I'll have a look. > Now, forget about C "variables" and "pointers" because you won't get > much far with those concepts. Ok, painful, but I'll try. > Objects exist - and we usually use names to refer to them. This line: > > a = 1 > > means "make the name 'a' refer to the object 1", or, "bind the name 'a' > to the instance of type int with value 1", or "let 'a' be a reference > to the object 1" > > This line: > > some_list[1] = 4 > > means "make the second element of some_list refer to the object 4", or > "alter some_list so its element [1] is a reference to the object 4" > > bind the name 'a' to the instance of type int with value 1", or "let > 'a' be a reference to the object 1" > > Note that some objects are immutable - like the number 1, which will > always be the number 1 (*not* an integer "variable" that can hold any > integer value). Other objects -like lists and dictionaries, by example, > or most user defined classes- are mutable, and you can change its > contents and properties. Modifying an object is not the same as > rebinding its name: > > x = [1,2,3] > y = x > x[1] = 4 > print x # [1, 4, 3] > print y # [1, 4, 3] Thanks to your explanation, I understand! > x = [1,2,3] > y = x > x = [1,4,3] > print x # [1, 4, 3] > print y # [1, 2, 3] > > You can test is two names refer to the same object using the is > operator: x is y. You will get True in the first case and False in the > second case. I don't quite get this "x is y" stuff yet. Let's go back the statement: x = [1,2,3] Do we then say: "[1,2,3] is x" or is it the other way around: "x is [1,2,3]" ??? I think it is the former in Python, whereas it would be the latter in C. So Python is like saying "I am Chris Carlen." This is actually completely ridiculous, since I am me, not my name. The name refers to me. I get that. Yet our spoken language puts it in a way which is backwards. Thanks for the input. -- Good day! ________________________________________ Christopher R. Carlen Principal Laser&Electronics Technologist Sandia National Laboratories CA USA [EMAIL PROTECTED] NOTE, delete texts: "RemoveThis" and "BOGUS" from email address to reply. -- http://mail.python.org/mailman/listinfo/python-list