python apply()函数
来源:互联网 发布:linux下如何删除用户 编辑:程序博客网 时间:2024/05/01 13:48
>>> help(apply)Help on built-in function apply in module __builtin__:apply(...) apply(object[, args[, kwargs]]) -> value Call a callable object with positional arguments taken from the tuple args, and keyword arguments taken from the optional dictionary kwargs. Note that classes are callable, as are instances with a __call__() method. <span style="color:#ff0000;">Deprecated since release 2.3. Instead, use the extended call syntax: function(*args, **keywords).</span>>>>
args是一个包含将要提供给函数的按位置传递的参数的元组。如果省略了args,任何参数都不会被传递。
kwargs是一个包含关键字参数的字典。
apply()的返回值就是object()的返回值。
apply()的元素参数是有序的,元素的顺序必须和object()形式参数的顺序一致。
1》执行不带参数的函数
def say(): print 'hello python!' say()apply(say)结果:
hello python!
hello python!
2》函数只带元组的参数
def say(a): print asay('hello python!')apply(say,("hello python!",))def say_again(a,b): print a,bsay_again('hello','python!')apply(say_again,('hello','python!'))结果:
hello python!
hello python!
hello python!
hello python!
3》函数带关键字参数
def say(a=1,b=2): print a,b def haha(**kw): print kw print type(kw) say() say(kw)#将kw传给a, b取默认值 apply(say,(),kw) haha(a='hello',b='python!')结果:
{'a': 'hello', 'b': 'python!'}
<type 'dict'>
1 2
{'a': 'hello', 'b': 'python!'} 2
hello python!
又如:
def say(x,y,a=1,b=2): print x,y,a,b def haha(*args,**kw): print args,type(args) print kw,type(kw) apply(say,args,kw) haha(1,2,a='hello',b='python!')
结果:
(1, 2) <type 'tuple'>
{'a': 'hello', 'b': 'python!'} <type 'dict'>
1 2 hello python!
1 0
- python apply()函数
- python apply()函数
- python apply()函数
- python apply()函数
- Python apply()函数
- python apply函数的用法
- 有关python的apply()函数
- python apply函数的用法
- 【Python】Pandas的apply函数使用示例
- Python中map,filter和apply函数
- 【Python】Pandas——apply函数
- Python】Pandas的apply函数使用示例
- python apply
- python apply
- python函数式编程:apply, map, lambda和偏函数
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的几个内建函数:apply(),filter(),map(),reduce(
- 今后,若你的公众号还按老方式发广告,罚款高的可达百万。有公众号已经被惩处了。
- jq實現網頁個性title
- 如何将Android studio中Library发布到Jcenter
- iOS 自定义转场动画篇
- Android仿微信朋友圈图片查看器
- python apply()函数
- 关于bootstrap中tab的使用
- Access restriction: The type 'Resource' is not API (restriction on required library 'G:\JAVA\jdk\lib
- 再点一次退出最简单逻辑
- 一种通过AIDL实现DLNA共享服务的方法
- Navicat数据库管理软件
- 带下拉列表提示语的TextView
- 一步一步解析java集合框架HashMap源码(3)
- java编程300例:2.输出程序后面的参数