[Tutor] Shorten Code.
ALAN GAULD
alan.gauld at btinternet.com
Sat Nov 19 09:54:30 CET 2011
>
>> > > for var in [value,value_1]:
>> > > var = "green"
>>
>> > Um, that won't work. You typed that example too quickly.
>
>
>> Excuse: It was early morning and I hadn't had any coffee...
>
>> In your defense Alan, after you typed that code in your response you
>mentioned
> the necessity of defining the variables:
Yes, but that's still not good enough. The loop above only sets var to green
>it doesn't change the values of the variables in the list. That's why you need
>to use enumerate and access them via an index. Basically its just not a good
>plan, best to avoid it.
Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111119/e6c8d013/attachment.html>
More information about the Tutor
mailing list