def calc_prod(lst):
def cj():
num = 1
for i in lst:
num = num *i
return num
return cj
f = calc_prod([1, 2, 3, 4])
print f()
def cj():
num = 1
for i in lst:
num = num *i
return num
return cj
f = calc_prod([1, 2, 3, 4])
print f()
2019-10-22
print map(str.capitalize, ['adam', 'LISA', 'barT'])
2019-10-19
def format_name(s):
ss=''
if s[0]>'Z':
ss=ss+chr(ord(s[0])-32)
else:
ss=ss+s[0]
for i in range(1,len(s)):
if s[i]<'a':
ss=ss+chr(ord(s[i])+32)
else:
ss=ss+s[i]
return ss
print map(format_name, ['adam', 'LISA', 'barT'])
ss=''
if s[0]>'Z':
ss=ss+chr(ord(s[0])-32)
else:
ss=ss+s[0]
for i in range(1,len(s)):
if s[i]<'a':
ss=ss+chr(ord(s[i])+32)
else:
ss=ss+s[i]
return ss
print map(format_name, ['adam', 'LISA', 'barT'])
2019-10-19
def __init__(self, num):
self.l=[]
f=0
g=1
x=1
while x<=num:
self.l.append(f)
g=g+f
f=g-f
num-=1
def __len__(self):
return len(self.l)
def __str__(self):
return str(self.l)
self.l=[]
f=0
g=1
x=1
while x<=num:
self.l.append(f)
g=g+f
f=g-f
num-=1
def __len__(self):
return len(self.l)
def __str__(self):
return str(self.l)
2019-10-17
if self.score<s.score:
return 1
elif self.score>s.score:
return -1
else:
if self.name<s.name:
return -1
elif self.name>s.name:
return 1
else:
return 0
return 1
elif self.score>s.score:
return -1
else:
if self.name<s.name:
return -1
elif self.name>s.name:
return 1
else:
return 0
2019-10-17
def __init__(self, name, gender, course):
super(Teacher,self).__init__(name,gender)
self.course=course
super(Teacher,self).__init__(name,gender)
self.course=course
2019-10-15
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
2019-10-15
最赞回答 / 慕前端0053732
python3的版本问题,直接运行print(sorted(['bob','about', 'Zoo', 'Credit'], key = lambda x: x.upper()))就可以了。也不用定义函数和调用
2019-10-14
最新回答 / 罗夏luo
python3需要改一下
import functools class Student(object): def __init__(self, name, score): self.name = name self.score = score def __str__(self): return '(%s: %s)' % ...
2019-10-13
最新回答 / wztg
带双下划线的类的外部不能访问 但是你在类的外部调用p1 = Person('bob'),p2 = Person('lisa')没有在外部直接访问__count,而是调用类的初始化函数__init__输出的结果,__init__是类的内部函数可以访问类中带双下划线的属性
2019-10-11
最新回答 / 慕用1366169
def prod(x, y): return x * y<...code...>def calc_prod(lst): def calc(num): lst.append(num) return reduce(prod, lst) return calcf = calc_prod([1, 2, 3, 4])print f(5)能打印出:120
2019-10-08