python:2017.11.3
来源:互联网 发布:筛选出的数据求和 编辑:程序博客网 时间:2024/05/17 09:38
函数
>>> def Hello(name): 'Hello+name' return 'hello'+name>>> Hello.__doc__'Hello+name'>>> Hello('yc')('hello', 'yc')
1、当形参改变时,实参不改变
2、当参数为列表是,形参改变,实参也会改变
关键字参数
>>> def Hello(first, second): return first+second>>> Hello(second="yc",first='Hello')'Helloyc'
1、将位置参数放在关键词参数前面可以同时使用
收集参数
>>> def test (*a): return a>>> test(1,2,3)(1, 2, 3)
>>> def test (x,y,z,*a,**b): print x print y print z print a print b>>> test(1,2,3,4,5,6,7,aa=1,bb=2)123(4, 5, 6, 7){'aa': 1, 'bb': 2}
1、收集其余位置的参数,没有时为空元组
2、**为字典
>>> def test (a,b): return a+b>>> a=(1,2)>>> test(*a)3
1、调用函数时用*,分配列表中的数
2、**分配字典
全局变量
>>> x=1>>>> def test(): global x =x+1SyntaxError: invalid syntax>>> def test(): global x x=x+1>>> test()>>> x2
阅读全文
0 0
- python:2017.11.3
- python 2 & python 3
- Python 3 会害死 Python
- Python--python基础知识(3)
- python(3)
- Python(3)
- python - 3
- python-3
- python 3
- python 2 和 python 3
- Python print 语句(Python 2 与 Python 3)
- Python 初学者 入门 应该学习 python 2 还是 python 3?
- 【python基础知识】python 2 与python 3 的差异
- Python编程 (Programming Python, 3rd Edition)
- 【Python开发web】(3) -- Python基础之一
- Python 3 与Python 2的区别
- Python 3 与Python 2的区别
- Python基础 3----Python函数及类
- 变量类型转换
- 人工智能加剧互金马太效应,爱钱进凭什么领先?
- 欧拉筛(bzoj 2818: Gcd)
- 初用Git之小结(一)
- 代价地图的层级结构
- python:2017.11.3
- list json序列化
- Container With Most Water
- TOP100summit:【分享实录-猫眼电影】业务纵横捭阖背后的技术拆分与融合
- CVPR2017-最新目标检测相关
- 基础知识总结:枚举
- 基础篇 Android IntentService
- 文章标题
- 正则表达式