def cmp_ignore_case(s1, s2):
if s1[0].upper()>s2[0].upper():
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1[0].upper()>s2[0].upper():
return 1
else:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-08-18
关于闭包装饰器http://www.cnblogs.com/ma6174/archive/2013/04/15/3022548.html
2016-08-18
capitalize() 首字母大写,其余全部小写
upper() 全转换成大写
lower() 全转换成小写
title() 标题首字大写,如"i love python".title() "I love python"
upper() 全转换成大写
lower() 全转换成小写
title() 标题首字大写,如"i love python".title() "I love python"
2016-08-18
可能是这个意思?
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
print(Person.__count)
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except:
print "attributeerror"
class Person(object):
__count = 0
def __init__(self, name):
Person.__count += 1
print(Person.__count)
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except:
print "attributeerror"
2016-08-18
def cmp_ignore_case(s1, s2):
if s1.lower()<s2.lower():
return -1
if s1.lower()>s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.lower()<s2.lower():
return -1
if s1.lower()>s2.lower():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2016-08-17