class BStudent(Student,BasketballMixin):
def __init__(self):
super(BStudent,self).__init__()
class FTeacher(Teacher,FootballMixin):
def __init__(self):
super(FTeacher,self).__init__()
s = BStudent()
print s.skill()
t = FTeacher()
print t.skill()
def __init__(self):
super(BStudent,self).__init__()
class FTeacher(Teacher,FootballMixin):
def __init__(self):
super(FTeacher,self).__init__()
s = BStudent()
print s.skill()
t = FTeacher()
print t.skill()
2018-03-07
def prod(x, y):
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
return x*y
print reduce(prod, [2, 4, 5, 7, 12])
2018-03-07
def format_name(s):
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
return s.capitalize()
print map(format_name, ['adam', 'LISA', 'barT'])
2018-03-07
def cmp_ignore_case(s1, s2):
if str.lower(s1) > str.lower(s2):
return 1
elif str.lower(s1) < str.lower(s2):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if str.lower(s1) > str.lower(s2):
return 1
elif str.lower(s1) < str.lower(s2):
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-03-07
import math
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) == int(math.sqrt(x))
print filter(is_sqr, range(1, 101))
2018-03-07
def cmp_ignore_case(s1, s2):
if s1.capitalize() > s2.capitalize():
return 1
if s1.capitalize() < s2.capitalize():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
if s1.capitalize() > s2.capitalize():
return 1
if s1.capitalize() < s2.capitalize():
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2018-03-07
最赞回答 / 慕村1591618
这个需要每次新创建一个实例的时候将count+1,所以count的自增应该放在__init__函数里,这样每创建一个实例自动调用__init__就可以达到count计数的功能
2018-03-06
import math
def is_sqr(x):
return x and math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
and也可以吧?
def is_sqr(x):
return x and math.sqrt(x)%1==0
print filter(is_sqr, range(1, 101))
and也可以吧?
2018-03-06
time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
2018-03-06
已采纳回答 / 凌悦
首先,s > 0, 考虑的是s的长度大于0的,则应写 len(s) > 0, 为了排除首尾空字符串或\n\t等情况,应改写为len(s.strip()) > 0其次,len()函数不适用于s为None的情况,故 s 不能None故最终def is_not_empty(s): return s and len(s.strip()) > 0
2018-03-05
最赞回答 / 流年丶岁月
很简单的。你直接 L2 = sorted(['Bart', 'Adam', 'Lisa']) 就是你说的意思。但是这里的L1不是字符串的list,里面都是Person的实例。对这些实例肯定就没有办法按照默认排序方式了,要自己添一个排序方式告诉它,也就是 L2 = sorted(L1, lambda x,y: cmp(x.name,y.name))
2018-03-05