溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python 高階函數: Partial(偏函數)

發布時間:2020-06-01 06:09:15 來源:網絡 閱讀:1496 作者:虎皮喵的喵 欄目:編程語言

格式:

        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(偏函數)

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女