[cc lang="python"]class Message:
def __init__(self, aString):
self.text = aString
def printIt(self):
print self.text
m1 = Message("Hello world")
m2 = Message("So long, it was short but sweet")
note = [m1, m2] # put the objects in a list
for msg in note:
msg.printIt() # print each message in turn
[/cc]
详细指南
No comments:
Post a Comment