本文共 391 字,大约阅读时间需要 1 分钟。
要求:
创建一个类People
包含属性name, city 可以转换为字符串形式(__str__
) 包含方法moveto (self,newcity)用新的城市去替代之前的城市 可以按照city排序 (__lt__
) 创建4个人对象 放到列表进行排序
class People(): def __init__(self,name,city): self.name=name self.city=city def __str__(self): return'<%s:%s>'%(self.name,self.city) def moveto(self,newcity): self.city=newcity def __lt__(self,other): return self.city
转载地址:http://cyhgn.baihongyu.com/