[Tutor] more newbie questions: variables without a value

alan.gauld@bt.com alan.gauld@bt.com
Fri, 29 Jun 2001 10:53:24 +0100


> in the following code..

Which looks suspiciously familiar...

> m1 = Message("Hello World")
> m2 = Message("So long, it was short bu sweet.")

create two message objects

> 
> note = [m1, m2]

put them in a list

> for msg in note:

assign msg to each item in the list

> 	msg.printIt()

perform an action on msg

Its no different to:

for n in range(5):
   print n

range(5) is identical to:
[0,1,2,3,4]

so we could have written:

for n in [0,1,2,3,4]:
   print n

> the line: "for msg in note:" doesn't seem to make sense 
> because "msg" has no value nor is it pointing to "note".

Check my tutor page on loops:

http://www.crosswinds.net/~agauld/tutloops.htm

for more detail.

Alan G.