码迷,mamicode.com
首页 > 其他好文 > 详细

偏函数

时间:2016-06-04 23:25:12      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

t = int(123445)
print(t)
t = int(123, 4)
print(t)
#23

t = int(123, base = 8)
print(t) 
#83

t = int(12, 16)
print(t)
#18

def int2(x, base = 8):
    return int(x, base)
t = int2(12)
print(t)

import functools
int2 = functools.partial(int, base = 2) #这里固定了int的参数base
t = int2(1111)
print(t)
#15
#上面代码相当于
kw = {base : 2}
t = int(1000, **kw)
print(t)
#8

max2 = functools.partial(max, 10)

t = max2(1, 3, 5, 6) #实际上会把10作为*args的一部分自动加到左边,也就相当于max(10, 1, 3, 5, 6)
print(t)
#10

 

偏函数

标签:

原文地址:http://www.cnblogs.com/rain-1/p/5559776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!