今天学的是class(类),见ex40py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
class Sayer(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def say(self):
for line in self.lyrics:
print line
english = Sayer(["first",
"second",
"third"])
mather = Sayer(["1111111",
"22222222"])
english.say()
mather.say()
有如下输出:
first
second
third
1111111
22222222