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 ...
随机推荐
- pycharm的list的应用
li = [11,22,22,33,44] v = li.count(22) print (v) #输出结果2 #计算元素的次数 count的应用 li = [11,22,33,22,44] li.e ...
- Codeforces 126B. Password (KMP)
<题目链接> 题目大意:给定一个字符串,从中找出一个前.中.后缀最长公共子串("中"代表着既不是前缀,也不是后缀的部分). 解题分析:本题依然是利用了KMP中next数 ...
- PMP测试实践- 内附PMBOK中字与备考资料
最近笔者考了PMP(Project Management Professional )项目管理专业人士认证考试,主要为了系统学习下项目管理的整个过程与方法,结合PMP的理论与工作实践去更好的完成项目工 ...
- Objective-C中整数与字符串的相互转换
2013/4/15整理: 将整数转换成字符串 Convert Integer to NSString: 方法一: int Value = 112233; NSString *ValueString = ...
- 信息学奥赛辅导经验谈 & 问题教学法中的学生思维能力培养
转载来自朱全民名师工作室 信息学奥赛辅导经验谈 全国青少年信息学奥林匹克分区竞赛(简称NOI)是经中国科协.国家教育部批准,由中国计算机学会主办的一项全国性的青少年学科竞赛活动.随着信息学奥林匹克竞赛 ...
- dubbo+zookeeper报错:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method可能的错误原因有三个前两个是从网上摘得, 第三个是自己解决的 1.需要进行 ...
- python学习:输入设置
输入设置 输入用户名和密码 代码: _user = "alex"_password = "abc123" username = input("User ...
- mysql学习3
1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引, 会保存在额外的文件中. 作用: 约束 加速查找 1.1.建立索引 a.额外的文件保存特殊的数据结构 ...
- 微信小程序统计分析
在微信公众平台社区看到一个不错的东西,小博统计:https://www.wxappdev.com/:用于微信小程序统计分析.
- Round A - Kick Start 2019
a.链接:https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050e01/00000000000698d6 题意: ...