On 11/15/2016 07:39 PM, jf...@ms4.hinet.net wrote: > Michael Torrie at 2016/11/15 10:43:58PM wrote: >> Seems like you're still not understanding Python variables. > > I do, just not get used to it yet:-)
No you don't yet. See below. > Why? the name "tblm" is already exist and is a mutable one, should be > changed intuitional by "tblm=tbli". If I really need a new list, I > can create one by using a new name. Python shouldn't have its finger > in my pie:-( No, names are not mutable per se. Objects can be. If the object is mutable you can mutate it: someobject.some_mutate_method(foo) or some_list[1] = 5 The latter is actually syntactic sugar for something more akin to this: some_list.__setattr__(1,5). Note that this throws out the reference to the object that used to be held by slot 1, and now refers to the new object, 5. Names are, well, just names. They refer to objects, which may or may not be mutable. And multiple names can refer to the exact same object. Internally, variables are stored in dictionaries: >>> a = 5 >>> globals['a'] 5 And in fact in Python many primitive objects like numbers and strings are immutable. They cannot ever change once they are brought into existence. Expressions such as mathematical equations result in new objects being created (number objects can be reused and are often cached). The assignment operator does not by default mutate an object. Instead it makes the variable (the name) refer to the new object, the result of the RHS. Now this may seem like I've contradicted myself, seeing as I used the example above to show how = can mutate a list-like object. But if you understand the underlying mechanism for holding names, it's actually consistent. The globals object is a dictionary and is itself mutable. But when we assign a new object to a particular dictionary key, it tosses out the old reference and makes the key now refer to the new object. It does not do anything to the old object itself. Anyway, don't think we can make things much clearer than that. >> You're getting hung up on the names, when you should be >> concentrating on what the names refer to. > > That's one problem I was concerned. Human beings are very deeply > binding on words (names?). We think in words, talk in words, > communicate in words. Actually we are living in words. I really don't > like that when I said "John is a boy" and was told "No, John is a dog > now":-) Not quite sure where you're going with that. I would think the idea of labels on objects would be fairly natural. I could stick a label that says "chair" on a chair, and then later move that label to the couch. Same label, different object. Whether the label makes sense is up to you. -- https://mail.python.org/mailman/listinfo/python-list