def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-05-21
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2018-05-21
import string
def cmp_ignore_case(s1, s2):
if(string.upper(s1) > string.upper(s2)):
return 1
if(string.upper(s1) < string.upper(s2)):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
def cmp_ignore_case(s1, s2):
if(string.upper(s1) > string.upper(s2)):
return 1
if(string.upper(s1) < string.upper(s2)):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-05-21
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)
2018-05-21
def strandenglish(name):
return name[0].upper()+name[1:].lower()
print(list(map(strandenglish,['adam','LISA','barT'])))
or
def strandenglish2(name):
return name.capitalize()
print(list(map(strandenglish2,['adam','LISA','barT'])))
return name[0].upper()+name[1:].lower()
print(list(map(strandenglish,['adam','LISA','barT'])))
or
def strandenglish2(name):
return name.capitalize()
print(list(map(strandenglish2,['adam','LISA','barT'])))
2018-05-19
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-19
import math
print filter(lambda x:(int)(math.sqrt(x))==math.sqrt(x), range(1,101))
print filter(lambda x:(int)(math.sqrt(x))==math.sqrt(x), range(1,101))
2018-05-18
def format_name(s):
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
return s[0].upper()+s[1:].lower()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-05-18
答案应该是这样的:
越来越觉得任务和 本节讲的不怎么承上启下,不怎么好。
class Person(object):
__count = 0
def __init__(self, name):
Person.__count = Person.__count + 1
self.name = name
print self.__count
p1 = Person('Bob')
p2 = Person('Alice')
print p1.__count
越来越觉得任务和 本节讲的不怎么承上启下,不怎么好。
class Person(object):
__count = 0
def __init__(self, name):
Person.__count = Person.__count + 1
self.name = name
print self.__count
p1 = Person('Bob')
p2 = Person('Alice')
print p1.__count
2018-05-18