gll89的个人博客分享 http://blog.sciencenet.cn/u/gll89

博文

[转载]functools.partial() in python

已有 1357 次阅读 2019-5-16 21:00 |个人分类:Python|系统分类:科研笔记|文章来源:转载

functools.partial(func[,*args][, **keywords])

  • Return a new partial object which when called will behave like func called with the positional arguments args and keyword arguments keywords

For example, partial() can be used to create a callable that behaves like the int() function where the base argument defaults to two:

>>> from functools import partial
>>> basetwo = partial(int, base=2)
>>> basetwo.__doc__ = 'Convert base 2 string to an int.'
>>> basetwo('10010')
18



https://docs.python.org/2/library/functools.html?highlight=functools%20partial#functools.partial



https://wap.sciencenet.cn/blog-1969089-1179464.html

上一篇:Atom如何使用go to definition
下一篇:[转载]DL tricks
收藏 IP: 60.191.2.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-3 08:45

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部