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 ...
随机推荐
- 机器A定时发文件给机器B-FTP实现
机器A发文件的虚拟机 机器B收文件的虚拟机 机器A: 确认linux安装了ftp包,能启用ftp命令 定时器使用的是crontab 定时器设置步骤: 1.进入root用户 2.service cron ...
- labview下载地址
ftp://ftp.ni.com/evaluation/labview/ekit/other/downloader
- Cookie、cookie使用方法
Cookie.cookie使用方法.保存用户名密码 //设置Cookie, //cname 获取时所需参数 //username,password 用于记住账号密码,如果只要存一个参数 passwor ...
- JDK解压版制作
今天上 甲骨文 的官网,想下载一个 解压版的 jdk 1.8 结果发现: 没有解压版,只有exe版本.于是就搜索制作方法. 具体就是,双击exe版本,在最后关头要安装的时候, 重点来了! 跟他皮一下 ...
- 2019年5月1日起安卓应用应基于API 26开发,那么API等级是啥?
2019年5月1日起安卓应用应基于API 26开发,那么API等级是啥? 转 https://www.ithome.com/html/android/372234.htm 据泰尔终端实验室公众微信 ...
- Gatsby上手指南 - 让你的静态网站用react来高逼格的写
注意:Gatsby V2版本安装及使用问题请移步<Gastby V2安装过程中常见问题>,此文较旧,主要针对V1版Gatsby而介绍 前言 一直以来都是用之前比较流行的静态网站生成器Hex ...
- CloseableHttpClient获取https请求不验证证书
创建---调用 CloseableHttpClient httpclient = getHttpsClient(); /** * 获取https连接(不验证证书) * * @return */ pri ...
- 记一次非常规方法对接硬件设备(Grason Stadler GSI 61)
Grason Stadler GSI 61 电测听设备 (写下设备的名字, 希望别人遇坑可以搜到) 对接说明 设备厂家提供自带的软件,但是没有找到接口说明.我们需要获取设备发送过来的数据. 厂家提供的 ...
- android BLE Peripheral 模拟 ibeacon 发出ble 广播
Android对外模模式(peripheral)的支持: 从Android 5.0+开始才支持. api level >= 21 所以5.0 之前设备,是不能向外发送广播的. Android中心 ...
- PHP生成图表pChart
pChart是一个开源的图表生成库,主要涉及3个Class:pChart.class, pData.class, pCache.class,可生成20多种简单或复杂的图表,支持PNG,JPG,GIF通 ...