为了账号安全,请及时绑定邮箱和手机立即绑定

python进阶

廖雪峰 移动开发工程师
难度中级
时长 3小时33分
学习人数
综合评分9.20
575人评价 查看评价
9.6 内容实用
9.0 简洁易懂
9.0 逻辑清晰
def calc_prod(lst):
def prod():
x = 1
for y in lst:
x = x * y
return x
return prod

f = calc_prod([1, 2, 3, 4])
print f()
def calc_prod(lst):
def lazy():
def xx(x,y):
return x*y
return reduce(xx,lst)
return lazy

f = calc_prod([1, 2, 3, 4])
print f()
def cmp_ignore_case(s1, s2):
a=s1.lower()
b=s2.lower()
if a > b:
return 1
if a < b:
return -1
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
看完了,但是做题时还是经常没想到曾经学过的,还是不熟悉,比如匿名函数、item、iteritems迭代什么的
原来有理数四则运算是分数运算?看了下面评论才知道。。。
import math
def is_sqr(x):
return math.sqrt(x)*10%10 == 0

print (list(filter(is_sqr, range(1, 101))))
def prod(x, y):
return x*y

print reduce(prod, [2, 4, 5, 7, 12])

python 内置函数果然好强大
def performance(unit):
def time_per(f):
def wrapper(n):
t1 = time.time()
result = f(n)
t2 = time.time()
print 'call ' + f.__name__ + '() in ' + str(t2 - t1) + unit
return result
return wrapper
return time_per
import time
def performance(f):
def fn(*args, **kw):
t1 = time.time()
result = f(*args, **kw)
t2 = time.time()
print 'call ' + f.__name__ + '() in ' + str(t2 - t1) + 's'
return result
return fn
这个多态。。。
这个异常处理啊
这个,完全没说明白啊
回去复习了sorted()、匿名函数,补了cmp()比较函数才看懂答案
课程须知
本课程是Python入门的后续课程 1、掌握Python编程的基础知识 2、掌握Python函数的编写 3、对面向对象编程有所了解更佳
老师告诉你能学到什么?
1、什么是函数式编程 2、Python的函数式编程特点 3、Python的模块 4、Python面向对象编程 5、Python强大的定制类

微信扫码,参与3人拼团

微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!

本次提问将花费2个积分

你的积分不足,无法发表

为什么扣积分?

本次提问将花费2个积分

继续发表请点击 "确定"

为什么扣积分?

举报

0/150
提交
取消