class Human(object): def __init__(self,name): #Object's variable self.name=name def intro(self): #Object's method print "My name is %s" % self.name mike = Human("Mike") don = Human("Don") print mike.name mike.intro() don.intro() |
---|
$ Mike $ My name is Mike $ My name is Don |
---|
class Human(object): def __init__(self,name): self.name=name def intro(self): print "My name is %s" % self.name class MetaHuman(Human): def think(self): print "%s is a philosopher..." % self.name mike = Human("Mike") don = MetaHuman("Don") mike.intro() don.think() |
---|
$ My name is Mike $ Don is a philosopher... |
---|