A tuple is a sequence of values. The values can be any type, and they are indexed by integers, so in that respect tuples are a lot like lists. The important difference is that tuples are immutable. Syntactically, a tuple is a comma-separated list of values:

To create a tuple with a single element, you have to include the final comma. Without the comma, Python treats (‘a’) as a string in parentheses. Another way to create a tuple is the built-in function tuple. With no argument, it creates an empty tuple.

If the argument is a sequence (string, list or tuple), the result is a tuple with the elements of the sequence. Most list operators also work on tuples. And the slice operator selects a range of elements.

But if you try to modify one of the elements of the tuple, you get an error. You cant modify the elements of a tuple, but you can replace one tuple with another.

from Thinking in Python

Tuples are immutable的更多相关文章

  1. Think Python - Chapter 12 Tuples

    12.1 Tuples are immutable(元组是不可变的)A tuple is a sequence of values. The values can be any type, and t ...

  2. Python学习笔记(迭代、模块扩展、GUI 、编码处理等)

    PythonIDLE中的编码处理 http://www.tuicool.com/articles/NbyEBr 原文标题:Python中实际上已经得到了正确的Unicode或某种编码的字符,但是看起来 ...

  3. 关于Python中数据对象的可变性

    先贴上Python官网中对数据模型描述的几段话.(在python官网的 语言参考>>数据模型 那部分) Every object has an identity, a type and a ...

  4. Python Tutorial 学习(五)--Data Structures

    5. Data Structures 这一章来说说Python的数据结构 5.1. More on Lists 之前的文字里面简单的介绍了一些基本的东西,其中就涉及到了list的一点点的使用.当然,它 ...

  5. python for data analysis 2nd 读书笔记(一)

    第一章相对简单,也么有什么需要记录的内容,主要用到的工具的简介及环境配置,粗略的过一下就行了.下面我们开始第二章的学习 CHAPTER 22.2Python Language Basics, IPyt ...

  6. Python开发 基礎知識 (未完代補)

    一.Python基本知識 1.Python屬高階語言,所編築的是字節碼 2.一般狀態statement 終止於換行,如需使用多數行編寫,可在行末加上 \,以表延續 但在 parentheses ( ) ...

  7. [Python Essential Reference, Fourth Edition (2009)]读书笔记

    Python programs are executed by an interpreter. When you use Python interactively, the special varia ...

  8. python 删除元组元素

    #create a tuple tuplex = "w", "j" ,"c", "e" print(tuplex) #t ...

  9. A Complete Tutorial to Learn Data Science with Python from Scratch

    A Complete Tutorial to Learn Data Science with Python from Scratch Introduction It happened few year ...

随机推荐

  1. Scratch单机版下载

    Scratch单机版下载 这两个地址速度比较快: Adobe Air:http://7dx.pc6.com/wwb5/AdobeAIR2800127.zip Scratch :http://7dx.p ...

  2. Crazyflie 2.0 System Architecture

    Crazyflie 2.0架构包含两个微控制器: A NRF51, Cortex-M0, 用于实现无线通信和电源管理: (1)按键开关逻辑(ON/OFF logic) (2)控制给其它系统供电(STM ...

  3. 杭电1596 find the safest road

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. android AudioManager AUDIOFOCUS

    如今開始做音乐播放器的模块.遇到了几个问题 当播放音乐的过程中,去调节音量或者情景模式中的铃声设置,结果会有两种声音同一时候响起. 引起此问题的解决办法是音乐焦点问题没弄清 现分析一下音乐焦点的几个属 ...

  5. Maven传递依赖的时候,同名包不同版本号的包均会下载,可是编译的时候,仅仅会载入一个高版本号的。

    描写叙述,在一个Maven项目中.同一时候依赖了spring-tomcat-weaver  和  struts-core 包.可是spring-tomcat-weaver 须要commons-dige ...

  6. zzulioj--1712--Monty Hall problem(蒙提霍尔问题)

     1721: Monty Hall problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 186  Solved: 71 SubmitSt ...

  7. 15-11-23:system指令

    CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本.文件系统版本) 1. appwiz.cpl:程序和功能 2. calc:启动计算器 3. certmgr ...

  8. POJ 3469 Dinic (二元关系)

    题意: 思路: //By SiriusRen #include <queue> #include <cstdio> #include <cstring> using ...

  9. ES6 | 关于class类 继承总结

    子类必须在constructor方法中调用super方法,否则新建实例时会报错.这是因为子类没有自己的this对象,而是继承父类的this对象,然后对其进行加工.如果不调用super方法,子类就得不到 ...

  10. 【算法】Floyd-Warshall算法(任意两点间的最短路问题)(判断负圈)

    求解所有两点间的最短路问题叫做任意两点间的最短路问题. 可以用动态规划来解决, d[k][i][j] 表示只用前k个顶点和顶点i到顶点j的最短路径长度. 分两种情况讨论: 1.经过顶点k,  d[k] ...