標籤:title ESS xtend ret int hit err roc ges
格式:
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進位數, 傳回值是十進位數
##自訂使用
def int2(x, base=2):
return int(x, base)
print "int2('1010101'):", int2('1010101')
二、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. Ifmore arguments are supplied to the call, they are appended to args. Ifadditional 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')
int4 = functools.partial(int, ‘2’) #int4:將int函數的x參數設定為預設值‘2’ ,其base預設為十進位
print "int4('2'):", int4()
python 高階函數: Partial(偏函數)