新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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(偏函数)
本文URL:http://wjwzjz.com/article/ppocej.html
在线咨询
服务热线
服务热线:028-86922220
TOP