Python編程:partial偏函數(shù)
發(fā)布時(shí)間:2021-11-23 點(diǎn)擊數(shù):670
# -*- coding: utf-8 -*- # @File : partial偏函數(shù).py # @Date : 2018-05-30 # @Author : Peng Shiyu from functools import partial # 默認(rèn)按十進(jìn)制轉(zhuǎn)換 r1 = int("12") print(r1, type(r1)) # 12 <class 'int'> # 按二進(jìn)制轉(zhuǎn)換 r2 = int("0101", base=2) print(r2, type(r2)) # 5 <class 'int'> # 使用偏函數(shù), 改造原有的int函數(shù) int2 = partial(int, base=2) r3 = int2("0101") print(r3, type(r3)) # 5 <class 'int'>