最赞回答 / sph37
class Person(object): passp1 = 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)print L2[0].nameprint L2[1].nameprint L2[2].name
2016-04-15
已采纳回答 / Uno菜鸟
fn=performance(f),传入f函数,在performance函数里面进行包装加"新技能",里面的fn只是对f函数包装加了新技能后的新函数,要返回的是加了“新技能”后的函数,自然就返回的是fn。
2016-04-14
import json
class Students(object):
def __init__(self):
self.st=r'["Tim","Bob","Alice"]'
def read(self):
return self.st
s = Students()
print json.load(s)
class Students(object):
def __init__(self):
self.st=r'["Tim","Bob","Alice"]'
def read(self):
return self.st
s = Students()
print json.load(s)
2016-04-14
import math
def is_sqr(x):
return math.sqrt(x)
print filter(len(is_sqr)<3, range(1, 101))
def is_sqr(x):
return math.sqrt(x)
print filter(len(is_sqr)<3, range(1, 101))
2016-04-14