#Filename:doginsta.py
#类创建和调用方法
class Dog(object):
"define Dog class"
def setName(self,name):
self.name = name
def greet(self):
print("Hi,I am called %s." % self.name)
if __name__ == '__main__': #这一行写错,没有输出结果 should be:'__main__'
dog = Dog()
dog.setName("Sara")
print(dog.greet())
#--------------------------------------------------------
print("haha ,cuole!,wrong!pay attention to it '__main__'!")
#--------------------------------------------------------------
class Roster:
"students and teacher class"
teacher = "maya"
students = ['list',"kv" ]
def __init__(self,tn='mayun'):
self.teacher=tn
def add(self, sn):
self.students.append(sn)
def remove(self, sn):
self.students.remove(sn)
def print_all(self):
print("Teacher:", self.teacher)
print("Students:", self.students)
if __name__ == '__main__':
roster = Roster()
roster.add("tutu")
roster.print_all()
roster.remove("kv")
roster.print_all()