Python内置函数(64)——tuple
英文文档:
The constructor builds a tuple whose items are the same and in the same order as iterable‘s items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a tuple, it is returned unchanged. For example, tuple('abc')
returns ('a', 'b', 'c')
and tuple( [1, 2, 3] )
returns (1, 2, 3)
. If no argument is given, the constructor creates a new empty tuple, ()
.
说明:
1. 函数功能创建一个新的元组。
2. 不传入任何参数函数将创建一个空的元组。
- #不传入参数,创建空元组
- >>> tuple()
- ()
3. 函数可以接收1个可迭代对象作为参数,将使用可迭代对象的每个元素创建一个新的元组。
- #传入不可迭代对象,不能创建新的元组
- >>> tuple(121)
- Traceback (most recent call last):
- File "<pyshell#17>", line 1, in <module>
- tuple(121)
- TypeError: 'int' object is not iterable
- #传入可迭代对象。使用其元素创建新的元组
- >>> tuple('')
- ('', '', '')
- >>> tuple([1,2,1])
- (1, 2, 1)
- >>> tuple((1,2,1))
- (1, 2, 1)
4. 创建新的元组还可以使用一对括号的方式:
4.1 使用一对括号来创建空的元组。
- >>> a= ()
- >>> a
- ()
4.2 创建单个元素的元组时必须尾随逗号。
- >>> a = (1,)
- >>> a #a是元组
- (1,)
- >>> a = (1)
- >>> a #a是数值
- 1
4.3 创建多个元素的元组,依次用逗号隔开。
- >>> a = (1,2,3)
- >>> a
- (1, 2, 3)
Python内置函数(64)——tuple的更多相关文章
- Python内置函数(21)——tuple
英文文档: The constructor builds a tuple whose items are the same and in the same order as iterable's it ...
- Python内置函数(64)——classmethod
英文文档: classmethod(function) Return a class method for function. A class method receives the class as ...
- 【转】python 内置函数总结(大部分)
[转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...
- python 内置函数总结(大部分)
python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...
- Python | 内置函数(BIF)
Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...
- python 内置函数和函数装饰器
python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...
- Python 内置函数笔记
其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...
- python内置函数,匿名函数
一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...
- python内置函数大全(分类)
python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...
随机推荐
- myBase Desktop 6.5.1 无限期试用
清空安装目录下的"nyfedit.ini"文件的"App.UserLic.FirstUseOn="配置项的值
- Mac下brew安装JDK的教程
---恢复内容开始--- 安装命令: brew cask install java 默认应该会下载jdk7 也可以指定下载版本brew cask install java6 注意: brew inst ...
- Array库
/** * 查找元素在数组中出现的所有位置 * @param {要查找的数组} array * @param {要查找的元素} ele * @param {回调函数} callback */ func ...
- SSL/TLS抓包出现提示Ignored Unknown Record
SSL/TLS抓包出现提示Ignored Unknown Record 出现这种提示有两种情况.第一种,抓包迟了,部分SSL/TLS的协商数据没有获取,Wireshark无法识别和解析.第二种,数据包 ...
- spring 应用
Spring框架本身会托管bean. 1.使用时需要注意对于包本身扫描配置. 2.使用注解本身包需要在扫描路径下.
- hdu1814 Peaceful Commission
hdu1814 Peaceful Commission 题意:2-sat裸题,打印字典序最小的 我写了三个 染色做法,正解 scc做法,不管字典序 scc做法,错误的字典序贪心 #include &l ...
- Python爬虫爬取豆瓣读书
一,准备工作. 工具:win10+Python3.6 爬取目标:爬取图中红色方框的内容. 原则:能在源码中看到的信息都能爬取出来. 信息表现方式:CSV转Excel. 二,具体步骤. 先给出具体代码吧 ...
- CSS矩形、三角形等
1.圆形 CSS代码如下:宽高一样,border-radius设为宽高的一半 #circle { width: 100px; height: 100px; background: red; -moz- ...
- CSS面试细节整理(一)
最近面试时候发现自己最熟悉的css确实开发中好多细节没注意到,为了防止在栽跟头,打算从头到底捋一遍咯 语法部分: 1.css几种选择器的写法 (1)h1 em {color:red;} (后代选择器) ...
- CentOS7设置SVN自启动,提交报错,无权限.手动kill掉后重启,成功.
参考文档:http://tieba.baidu.com/p/5174054662 最近想尝试在CentOS7上搭建SVN服务.遇到的问题大致如题,我这边再详细描述一下. 虚拟机:VMware® Wor ...