python创建访问对象属性,python创建对象,class Critte
文章由Byrx.net分享于2019-03-23 07:03:19
python创建访问对象属性,python创建对象,class Critte
class Critter(object): '''A virtual pet''' def __init__(self, name): print 'A new critter has been born!' self.name = name def __str__(self): rep = 'Critter object\n' rep += 'name: ' + self.name + '\n' return rep def __cmp__(self, other): if self.name > other.name: return 1 if self.name < other.name: return -1 if self.name == other.name: return 0 def talk(self): print 'Hi. I'm', self.name, '\n'# maincrit1 = Critter('Poochie')crit1.talk()crit2 = Critter('Randolph')crit2.talk()print 'Printing crit1:'print crit1print 'Directly accessing crit1.name:'print crit1.name
相关内容
- python NameTag类,pythonnametag类,class NameTa
- python重写父类方法,python重写,class MyList
- python中使用self参数,pythonself参数,class Bag:
- python udp 服务器,pythonudp,import socke
- python虚函数定义,python函数定义,class Specia
- python的get set方法示例,pythongetset示例,class Critte
- 罗马数字,,import strin
- python多父类继承示例,python继承示例,class A:
- python udp示例,pythonudp,import socke
- python对象声明,python声明,class MixedN
评论关闭