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 ...
随机推荐
- Hbase API 简单封装
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- 【MSVC】_invalid_parameter和_invoke_watson
最近遇到一个崩溃问题,崩溃在CRT中,最后调用的函数是_invoke_watson.调用关系大概如下: _invoke_watson _invalid_parameter _invalid_param ...
- 建造者模式(Builder Pattern)
建造者模式(Builder Pattern) 它可以将多个简单的对象一步一步构建成一个复杂的对象. 意图:将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示. 主要解决:主要解决在软 ...
- DAY1 VS2017&CUDA10.01环境搭建
Visual Studio工程配置情况: VC++目录配置: C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.\common\lib\x64 C: ...
- python no module named _socket 原因
python no module named _socket 原因 Lib/site-packages 不在 sys.path 中
- SpringBoot使用Graylog日志收集
本文介绍SpringBoot如何使用Graylog日志收集. 1.Graylog介绍 Graylog是一个生产级别的日志收集系统,集成Mongo和Elasticsearch进行日志收集.其中Mongo ...
- Linux之环境搭建(二)
上一节介绍了PC机安装Ubuntu,本节来看看Ubuntu下安装VMWare,以及在VMWare中安装Windows10. 原本想使用免费的VMware Workstation Player 15,但 ...
- ajax 文件下载
作为一个后端开发人员,使用java 生成文件,提供前端下载,这个问题倒不大,可是让我们自己去下载文件的时候,这个问题就大了,对不起,我只对前端一知半解,并不精通,谢谢!! 需求如下:前端检索数据,后台 ...
- Oracle导入大数据量(百万以上)dmp文件,报错ora-12592 :包错误
进行自动化测试过程中,发现需要重新搭建一套自动化测试库,然后利用pl/sql对数据库导出: 进行导入后发现报错ora-12592 :包错误 原因分析,数据量过大,传输超时,需要在Oracle服务端以及 ...
- 转 the best for wcf client
原文:http://stackoverflow.com/questions/573872/what-is-the-best-workaround-for-the-wcf-client-using-bl ...