Python Learning-Partial function __ function

Source: Internet
Author: User
#-*-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 ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.