max()的key的运用
class Person:
def __init__(self,age):
self.age = age
a = Person(5)
s = Person(1)
d = Person(2)
z = Person(7)
x = Person(88)
c = Person(55)
v = Person(3)
b = Person(6)
obj_list = [a,s,d,z,x,c,v,b]
def func(obj):
return obj.age
k = max(obj_list,key = func)
print(k.age)
f = max(obj_list,key = lambda obj : obj.age)
print(f.age)