python高阶函数:Partial(偏函数)

格式:

成都创新互联公司主要从事成都网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务商城,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

        functools.partail(函数,函数的参数) -------> int(x, base) ----->  functools.partial(int, base)

一、int函数

官网介绍:class int(x,base=10)  #x为字符串数字, 默认该字符串数字是十进制数, 返回值是十进制数



#!/usr/bin/python

##普通使用
print "int('10001', 2):", int('10001', 2)  #字符串数字‘10001’是2进制数, 返回值是十进制数

python 高阶函数: Partial(偏函数)

##自定义使用

def int2(x, base=2):
    return int(x, base)
   
print "int2('1010101'):", int2('1010101')

python 高阶函数: Partial(偏函数)

二、partial函数

官网介绍:

  • functools.partial(func[,*args][, **keywords]

  • Return a new partial object which when called will behave like funccalled with the positional arguments args and keyword arguments keywords. If more arguments are supplied to the call, they are appended to args. If additional keyword arguments are supplied, they extend and override keywords.

import functools  #导入模块

int3 = functools.partial(int, base=2)  # int3: 将int函数的base参数设置为默认值2进制
print "int3('100'):", int3('100')

python 高阶函数: Partial(偏函数)

int4 = functools.partial(int, ‘2’)  #int4:将int函数的x参数设置为默认值‘2’ ,其base默认为十进制

print "int4('2'):", int4()

python 高阶函数: Partial(偏函数)


分享名称:python高阶函数:Partial(偏函数)
当前地址:http://lszwz.com/article/ppocej.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款