On 05/04/2013 12:13 AM, Jim Mooney wrote:
for num in listOfNumChars:
>     num = int(num)


It seems like people learning Python run into this very often.

I think the reason is that in most simple cases, it's easier and more
intuitive to think that the name IS the object:

x = 1
y = 2
print x + y

Even though I know it's not a precise description, when I see this code,
I think of it as "x is 1, y is 2, print x plus y". And you do get
expected result, which reinforces this intuition.

Of course, a more precise way to think is:

 name 'x' is assigned to object with value=1
 name 'y' is assigned to object with value=2
 sum values that currently have assigned names of 'x' and 'y'

Therefore, what you are really doing is:

for each object in listOfNumChars:
    assign name 'num' to object (this is done automatically by the loop)
    assign name 'num' to int(value that has currently assigned name 'num')


 -m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Oaths are the fossils of piety.  George Santayana

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to