Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

Michael Torrie torriem at gmail.com
Thu Jun 20 01:16:51 EDT 2013


On 06/18/2013 03:51 AM, Νίκος wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a  # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
> 
> I see, thank you Steven.
> 
> But since this is a fact how do you create complicated data structures 
> that rely on various variables pointing one to another liek we did in 
> C++(cannot recall their names) ?
> 

As Steve said Python provides all manner of data structures and the
means to create data structures.  Any data structure (trees, lists, etc)
can all be made easily in Python using Python's basic data structures,
if the built-in data structures are not sufficient.  It turns out that
lists, hashes (dicts), and classes can pretty much do anything with
having to much about with C-style pointers and such.

Do yourself a favor and forget about the low-level stuff in Python for
now.  You'll be more frustrated if you don't.

The real power and expressivity of Python comes from embracing the
abstractions that Python provides to your advantage.  There's a certain
elegance and beauty that comes from such things, which I believe really
comes from the elegance and beauty of LISP, some of which manages to
shine forth in Python, despite its deficiencies.  When I first learned
Python, I was impressed that some of the elegance that I remember from
Scheme (how to use lists as a basic type for example) was there, but in
a form that appealed to me.



More information about the Python-list mailing list