a='\t\t123\r\n'
a.strip()
结果:'abc'
写错了,结果是123
a.strip()
结果:'abc'
写错了,结果是123
2015-03-05
class Person(object):
__count = 0
@classmethod
def how_many(cls):
return Person.__count
def __init__(self, name):
self.name = name
Person.__count += 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
@classmethod
def how_many(cls):
return Person.__count
def __init__(self, name):
self.name = name
Person.__count += 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2015-03-04
class Person(object):
count = 0
def __init__(self, name):
self.name = name
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 += 1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2015-03-04
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-03-04
最赞回答 / joe2015
对list排序的函数sorted(l,cmp) 需要接受一个cmp参数,根据cmp(x,y)的返回值来确定排列顺序,如果返回1,则x在y的后面,返回0,无所谓,返回-1则x排在y的前面。
2015-03-04
aaa = ['bob', 'about', 'Zoo', 'Credit']
print sorted(aaa,key = str.lower)
print sorted(aaa,key = str.lower)
2015-03-03
def performance(unit):
def f1(f):
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
def f1(f):
@functools.wraps(f)
def f2(*args, **kw):
return f(*args, **kw)
return f2
return f1
2015-03-03
def performance(unit):
def f1(f):
def f2(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %s%s' % (f.__name__, (t1-t2), unit)
return r
return f2
return f1
def f1(f):
def f2(*args, **kw):
t1 = time.time()
r = f(*args, **kw)
t2 = time.time()
print 'call %s() in %s%s' % (f.__name__, (t1-t2), unit)
return r
return f2
return f1
2015-03-03