格式:
functools.partail(函數(shù),函數(shù)的參數(shù)) -------> int(x, base) -----> functools.partial(int, base)
一、int函數(shù)
官網(wǎng)介紹:classint
(x, base=10) #x為字符串?dāng)?shù)字, 默認(rèn)該字符串?dāng)?shù)字是十進(jìn)制數(shù), 返回值是十進(jìn)制數(shù)
#!/usr/bin/python
##普通使用
print "int('10001', 2):", int('10001', 2) #字符串?dāng)?shù)字‘10001’是2進(jìn)制數(shù), 返回值是十進(jìn)制數(shù)
##自定義使用
def int2(x, base=2):
return int(x, base)
print "int2('1010101'):", int2('1010101')
二、partial函數(shù)
官網(wǎng)介紹:
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 #導(dǎo)入模塊
int3 = functools.partial(int, base=2) # int3: 將int函數(shù)的base參數(shù)設(shè)置為默認(rèn)值2進(jìn)制
print "int3('100'):", int3('100')
int4 = functools.partial(int, ‘2’) #int4:將int函數(shù)的x參數(shù)設(shè)置為默認(rèn)值‘2’ ,其base默認(rèn)為十進(jìn)制
print "int4('2'):", int4()
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。