def calc_prod(lst):
def chengji():
sum =1
for a in lst:
sum = sum*a
return sum
return chengji
f = calc_prod([1, 2, 3, 4])
print f()
def chengji():
sum =1
for a in lst:
sum = sum*a
return sum
return chengji
f = calc_prod([1, 2, 3, 4])
print f()
2017-09-03
def __init__(self, num):
num, self.__N__ = int(num),int(num)
a,b,self.L = 0,1,range(self.__N__)
while num:
self.L[self.__N__ - num] = a
a,b = b,a+b
num -= 1
num, self.__N__ = int(num),int(num)
a,b,self.L = 0,1,range(self.__N__)
while num:
self.L[self.__N__ - num] = a
a,b = b,a+b
num -= 1
2017-09-03
def __cmp__(self, s):
if self.score < s.score and self.name < s.name:
return 1
elif self.score == s.score:
return 0
else:
return -1
if self.score < s.score and self.name < s.name:
return 1
elif self.score == s.score:
return 0
else:
return -1
2017-09-03
def cmp_ignore_case(s1, s2):
a=s1.lower()
b=s2.lower()
if a<b:
return -1
else:
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
a=s1.lower()
b=s2.lower()
if a<b:
return -1
else:
return 1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-09-02
# python3需要这样:
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
res = list(filter(is_sqr, range(1, 101)))
print(res)
import math
def is_sqr(x):
return math.sqrt(x) % 1 == 0
res = list(filter(is_sqr, range(1, 101)))
print(res)
2017-09-01
竟然支持python3
def count():
fs = []
for i in range(1, 4):
def f(m=i):
return m*m
fs.append(f)
return fs
f1,f2,f3=count()
print(f1())
print(f2())
print(f3())
def count():
fs = []
for i in range(1, 4):
def f(m=i):
return m*m
fs.append(f)
return fs
f1,f2,f3=count()
print(f1())
print(f2())
print(f3())
2017-09-01
所以说,为什么编程不能看国内的教材,哎,这作者是不是来欺负小白的,我怀疑,好像让小白敬畏大神,还是你只是为了完成网站建设,不认真开设教程吧,你只是为了交工吧,这样的话,不要让小白都放弃,你就造化有功了
2017-09-01
调个内置的函数
from operator import mul
def calc_prod(lst):
def lazy_prod():
return reduce(mul, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
from operator import mul
def calc_prod(lst):
def lazy_prod():
return reduce(mul, lst)
return lazy_prod
f = calc_prod([1, 2, 3, 4])
print f()
2017-09-01
很简单的想法:
import math
def is_sqr(x):
return math.sqrt(x)%1==0#python区分0和0.0 因此判断整数就可以用这个
print filter( is_sqr, range(1, 101))
import math
def is_sqr(x):
return math.sqrt(x)%1==0#python区分0和0.0 因此判断整数就可以用这个
print filter( is_sqr, range(1, 101))
2017-08-31