On 15/6/2013 6:53 μμ, Michael Torrie wrote:
On 06/15/2013 07:07 AM, Nick the Gr33k wrote:
result = mylist (since its a no-emoty list)

result.append('bar')
result is mylist
True

Never seen the last statement before. What does that mean?
result is mylist ????

Yes.  Surprisingling good question.

http://docs.python.org/3.3/reference/expressions.html#is
http://docs.python.org/3/reference/datamodel.html

One thing that you may find interesting is that what we often call
variables in Python, and which from your code's point of view look and
act like variables are in fact names.  Whereas in C, assignment can be
thought of as copy (a = b in C means that b's value is copied to a), in
Python assignment is associating a name with an object.  Thus a = b in
Python means that now the names a and b both are bound (reference to)
the same object.  That's why the "is" operator is there, to help one
know if two names point to the same object.

I bring this up on the list from time to time because I find it really
interesting and intellectually appealing the way Python works.  Hearkens
back to my class at uni on programming language theory.



(a = b in C means that b's value is copied to a)

in C:

a = memory chunk able to hold some specific type's value
b = memory chunk able to hold some specific type's value

a = b means

So we have 2 memory units hod, the same value.

in Python:

a and b you say are names, which still are memory chunks

In both situations we still have 2 memory units holding values, so hows that different?

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to