def f1(f):
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
2015-04-16
lambda: 'A'等价于return'A',相当于一个函数f,那么f()='A'.因此,p1.get_grade=f,p1.get_grade()=f()
2015-04-16
class Person(object):
count=0
def __init__(self,name):
self.name=name
Person.count=Person.count+1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
count=0
def __init__(self,name):
self.name=name
Person.count=Person.count+1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2015-04-16
def __init__(self, name, gender, **kw):
self.name = name
self.gender = gender
for k, v in kw.iteritems():
setattr(self, k, v)
这道题前几天才讲过,又忘记了,嗷嗷嗷
self.name = name
self.gender = gender
for k, v in kw.iteritems():
setattr(self, k, v)
这道题前几天才讲过,又忘记了,嗷嗷嗷
2015-04-16
class Students(object):
def read(self):
return r'["Tim","Bob","Alice"]'
def read(self):
return r'["Tim","Bob","Alice"]'
2015-04-15
class Person():
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
pass
xiaoming = Person()
xiaohong = Person()
print xiaoming
print xiaohong
print xiaoming==xiaohong
2015-04-15
def cmp_ignore_case(s1, s2):
return cmp(s1.lower(),s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
return cmp(s1.lower(),s2.lower())
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2015-04-15