为了账号安全,请及时绑定邮箱和手机立即绑定

大神们帮忙看看怎么会报这个错误__main__student object at 0x03199650

#-*- coding:utf-8 -*-

class Student(object):

    def __init__(self, name, score):

        self.name = name

        self.score = score

def __str__(self):

return '(%s:%s)'%(self.name,self.score)

__repr__ = __str__

def __cmp__(self,s):

if self.score == s.score:

return cmp(self.name,s.name)

return -cmp(self.name,s.name)

L = [Student('Lily',94),Student('Lucy',89),Student('Mary',60)]

print sorted(L)


正在回答

1 回答

这不是报错,你调用的是对象的地址,而不是属性

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
python进阶
  • 参与学习       255533    人
  • 解答问题       3038    个

学习函数式、模块和面向对象编程,掌握Python高级程序设计

进入课程

大神们帮忙看看怎么会报这个错误__main__student object at 0x03199650

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号