L2是一个LIST了,为什么最后输出不能写print L2?谢谢!
class Person(object): pass p1=Person() p1.name='Bart' p2=Person() p2.name='Adam' p3=Person() p3.name='Lisa' L1=[p1,p2,p3] L2 = sorted(L1,key = lambda x:x.name)#L2=sorted(L1,lambda p1,p2:cmp(p1.name,p2.name)) """print L2[0].name, print L2[1].name, print L2[2].name """ print L2
运行结果:[<__main__.Person object at 0x02D9B0B0>, <__main__.Person object at 0x02D9B090>, <__main__.Person object at 0x02D9B0D0>