[Tutor] changing char list to int list isn't working
Mitya Sirenef
msirenef at lightbird.net
Sun May 5 01:35:53 CEST 2013
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
More information about the Tutor
mailing list