Python笔记--tuple
来源:互联网 发布:淘宝贷款没还会怎么样 编辑:程序博客网 时间:2024/06/04 18:28
tuple时Python中的不可变序列类型,它在Python中起到什么作用呢?
- 在函数调用时传递不定长参数
通过使用元组使得Python的参数传递更加灵活。我们可以通过两种方式实现。一种是是在定义函数时,在最后一个形参前加’*’,表示它会将多余的实参同上一个实参合并成元祖传入。比如,
def func(arg1,*arg2): print arg1,arg2func('my','name','is','xiaoming') #my ('name', 'is', 'xiaoming')
第二种方法是,在调用函数时,我们将多余的参数打包到一个元组中,传入进去,比如,
def func(arg1,arg2): print arg1,arg2func('my',('name','is','xiaoming')) #my ('name', 'is', 'xiaoming')
当然如果你既用了*又在调用时传入了元组参数,则实际上传递进去的是元组内嵌套着元组。
2. 作为返回值
Python中返回值有三种类型。如果return后无任何内容,返回None;有一个元素,返货Object类型,有多个元素就以元组的方式返回了。
0 0
- Python笔记-tuple
- Python笔记--tuple
- 【Python笔记】list与tuple
- python学习笔记16:tuple, set, dictionary
- Python学习笔记 - list和tuple
- Python学习笔记<list和tuple>
- Python学习笔记<list,tuple,range再探>
- Python学习笔记 - 9.元组(Tuple)
- python 关于tuple的一些小笔记
- Python基础学习笔记5 tuple,set
- 【Python学习笔记】使用list和tuple
- Python学习笔记:list,tuple和str
- python学习笔记使用list和tuple
- Python开发学习笔记(6) - List,Tuple
- Python学习笔记02_list和tuple
- 01-python学习笔记:list和tuple
- Python学习笔记1-List,tuple
- Python---tuple
- 文章标题
- c++初学之函数
- 神马楚楚街上货助手
- 东东的轰炸游戏 (DFS+并查集)
- Streat 思锥 光锥之内就是命运,思锥之外则是无垠
- Python笔记--tuple
- RelativeLayout常用属性介绍
- c语言的文法产生式
- 对“移动产品经理”的理解
- java 常见的单例模式,推荐静态内部类
- Part 66 - Check及Uncheck所有CheckBox 同时删除多行数据记录的实现
- VS2013安装opencv-2.4.13
- spring整合mybatis升级
- Java的动态代理(dynamic proxy)