----- Original Message -----
From: "Patty" <pa...@cruzio.com>
To: "Alan Gauld" <alan.ga...@btinternet.com>
Sent: Monday, January 03, 2011 9:05 AM
Subject: Re: [Tutor] How does it work?
Hi Folks - I read this code and tried to parse it as a pop quiz for myself
;) and have a question, maybe 2 clarifications, below:
----- Original Message -----
From: "Alan Gauld" <alan.ga...@btinternet.com>
To: <tutor@python.org>
Sent: Monday, January 03, 2011 8:09 AM
Subject: Re: [Tutor] How does it work?
"Neo Vector" <neo_vec...@yahoo.com> wrote
Could you explain me how does it work, pls?
==============================
r = ''
r is an empty string
for c in 'abcd':
c takes the value of each letter in turn
r = c + r
When I first looked at this - I thought that the variable 'c' would have
had to be initialized
first earlier in the program. And I thought that the programmer would
input a single char or a single space. I wasn't thinking counting
variable for some reason. So is 'for c in', one or more of key words that
Python understands that a loop is here and to actually trigger counting in
a loop? Does it start with a 1 or 0 internally to do this?
I also realized a mistake I may have made - maybe I confused 'for c in'
with 'while c in'.
r=''
c="d"
while c in 'abcd':
r=c+r
Or
r=''
c="d"
while c in ['a', 'b', 'c', 'd']:
r=c+r
Also for myself I think I would have used different descriptive names for
variables so that would have been less likely to throw myself off. And
also doing this fast to see if I have learned.
I really feel comfortable with Python now after six months and my small
application is completed and looks really good. I don't know how I would
have been able to make the simplest, smallest GUI part of my application -
using Tkinter and PIL- fast without the references and explanations of
Wayne Werner and Alan - Thanks to those on the list who are so helpful!
Patty
strings can be added such that the result is the concatenation of the two
strings. So in this case:
r becomes the sum of its old value and the current value of c
repeat for the next value of c.
If that doesn't help then tell us which bit(s) of it you don't
understand.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor