#encoding=UTF-8
def format_name(s):
#return s.title() 直接可以将字符串第一位大写其他全部小写
#return s.capitalize() 第一个字母转为大学 其他小写
#return s.lower().title() 先吧字符串全部小写 然后再title()把首字符变大写
print map(format_name, ['adam', 'LISA', 'barT'])
def format_name(s):
#return s.title() 直接可以将字符串第一位大写其他全部小写
#return s.capitalize() 第一个字母转为大学 其他小写
#return s.lower().title() 先吧字符串全部小写 然后再title()把首字符变大写
print map(format_name, ['adam', 'LISA', 'barT'])
2018-05-04
try:
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
2018-05-04
print sorted(['bob', 'about', 'Zoo', 'Credit'], key=str.lower)
2018-05-03
def calc_prod(lst):
def list_dot():
s=1
for i in lst:
s=s*i
return s
return list_dot
f = calc_prod([1, 2, 3, 4])
print f()
def list_dot():
s=1
for i in lst:
s=s*i
return s
return list_dot
f = calc_prod([1, 2, 3, 4])
print f()
2018-05-02
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) % 1 == 0
print filter(is_sqr, range(1, 101))
2018-05-02
def cmp_ignore_case(s1, s2):
if s1.upper() < s2.upper():
return -1
if s1.upper() > s2.upper():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.upper() < s2.upper():
return -1
if s1.upper() > s2.upper():
return 1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-05-01
class Person(object):
__count = 0
def __init__(self, name):
Person.__count = Person.__count + 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError as e:
print 'attributeerror'
__count = 0
def __init__(self, name):
Person.__count = Person.__count + 1
self.name = name
print Person.__count
p1 = Person('Bob')
p2 = Person('Alice')
try:
print Person.__count
except AttributeError as e:
print 'attributeerror'
2018-05-01