英文文档:

  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的更多相关文章

  1. Python内置函数(21)——tuple

    英文文档: The constructor builds a tuple whose items are the same and in the same order as iterable's it ...

  2. Python内置函数(64)——classmethod

    英文文档: classmethod(function) Return a class method for function. A class method receives the class as ...

  3. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

  4. python 内置函数总结(大部分)

    python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...

  5. Python | 内置函数(BIF)

    Python内置函数 | V3.9.1 | 共计155个 还没学完, 还没记录完, 不知道自己能不能坚持记录下去 1.ArithmeticError 2.AssertionError 3.Attrib ...

  6. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  7. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

  8. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

  9. python内置函数大全(分类)

    python内置函数大全 python内建函数 最近一直在看python的document,打算在基础方面重点看一下python的keyword.Build-in Function.Build-in ...

随机推荐

  1. 0 - Dao层(数据访问层设计)

    1. Dao 使用接口设计 2. Dao 没有实现代码, 使用模板实现(通过DynamicProxy+Dapper) 3. 模板格式暂定使用Ader Template 来自为知笔记(Wiz)

  2. 原生js添加博客点击鼠标出小心心效果~~

    昨天刚申请成功JS权限,心血来潮想添加点东西,记得之前看到别人家博客首页点击鼠标的时候会出现炫酷的 “小心心”,自己也来搞一个.没有用jquery啥的框架,原生js写起来麻烦了点,不过主要是怕博客首页 ...

  3. EJS 入门学习

    EJS(Embedded JavaScript templates)是一个简单高效的模板语言,通过数据和模板,可以生成HTML标记文本.可以说EJS是一个JavaScript库,EJS可以同时运行在客 ...

  4. Vagrant 安装以及private_network配置

    (需先安装virtuabox,vagrant) 1.下载centos 7 镜像,vagrant box add ceshi 镜像名 或者是使用先前vagrant package出来的box,进行加载镜 ...

  5. WPF RadioButton的绑定

    1. 枚举类 public enum EnumDataTypes { Simulation, Test } 2. 枚举型与布尔型的转换 public class EnumToBooleanConver ...

  6. 英语口语练习系列-C41-食物词汇-鹊桥仙

    词汇 1, rice [raɪs] n. 稻:米饭 vt. 把-捣成米糊状 Rice: 米饭 | 大米 | 稻 2, bread [bred] n. 面包:生计 vt. 在-上洒面包屑 Bread: ...

  7. 如何让pandas表格直接转换为markdown表格

    https://stackoverflow.com/questions/33181846/programmatically-convert-pandas-dataframe-to-markdown-t ...

  8. java 新手指南

    Java新手指南 不小心走上了一条不归路的我 因为对可视化感兴趣,然后学了MFC,发现MFC好麻烦啊,不如开发APP吧,刚学开发APP,艹,居然是用java做开发,那只好学java了,,呜呜,不知道什 ...

  9. Tensor类型

    Tensor类型 1.Tensor有不同的数据类型,每种类型又有CPU和GPU两种版本: 2.默认的tensor类型是FloatTensor,t.set_default_tensor_type可以修改 ...

  10. h5软键盘挡住输入框问题解决(android)

    问题 移动端浏览器中的表单在部分android机型上测试,点击靠下的输入框时会遇到弹出的软键盘挡住输入框问题 ios可自身弹起(ios自身的调整偶尔也会出问题,例如第三方键盘会遮挡,原因是第三方输入法 ...