#-*-coding:utf-8-*-
#偏函数
#字符串转整型, default to 10-in
print int (' 12345 ')
#10进制
print int (' 12345 ', base=10)
#8进制 Print int ('
12345 ', base=8)
#2进制 print int ('
10000 ', base=2)
#16进制
print int (' 12345 '), base=16)
'
from the above:
int function has default parameter base=10.
How to create a base=16
default parameter function
'
def int16 (x) on a secondary basis: return
int (x,base=16)
print int16 (' 123 ')
'
python defines the Int16 form
of the function as a partial function. That is, on the basis of an existing
function, modifies its default parameters to get a
new function, while Python provides a
special Tool to create such a function:
functools.partial
' '
import functools
#16进制
int16 = functools.partial (int, BASE=16)
print int16 (' 123 ')
Int2 = functools.partial (int,base=2)
print int2 (' 1010 ')
int8 = Functools.partial (int,base=8)
print int8 (' 123 ')