不出结果!
为什么我在IDE上运行这个程序,结果出不来呢?
为什么我在IDE上运行这个程序,结果出不来呢?
2016-05-18
class Student(object):
def __init__(self,name,score):
self.name=name
self.score=score
def __str__(self):
return '(%s,%s)'%s(self.name,self.score)
__repr__=__str__
def __cmp__(self,s):
if self.name<s.name:
return -1
elif self.name>s.name:
return 1
else :
return 0
>>> L=[Student('Tim',99),Student('Bob',88),Student('Tom',77)]
>>> print sorted(L)
[<__main__.Student object at 0x02B23290>, <__main__.Student object at 0x02B23370>, <__main__.Student object at 0x02B233B0>]
代码是这样的,在IDE中结果上,为甚?
class Person(object):
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
def __init__(self, name, gender, score):
super(Student, self).__init__(name, gender)
self.score = score
def __str__(self):
return '(Student: %s,%s,%s)'%(self.name,self.gender,self.score)
s = Student('Bob', 'male', 88)
print s
举报