Tuples are immutable
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的更多相关文章
- 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 ...
- Python学习笔记(迭代、模块扩展、GUI 、编码处理等)
PythonIDLE中的编码处理 http://www.tuicool.com/articles/NbyEBr 原文标题:Python中实际上已经得到了正确的Unicode或某种编码的字符,但是看起来 ...
- 关于Python中数据对象的可变性
先贴上Python官网中对数据模型描述的几段话.(在python官网的 语言参考>>数据模型 那部分) Every object has an identity, a type and a ...
- Python Tutorial 学习(五)--Data Structures
5. Data Structures 这一章来说说Python的数据结构 5.1. More on Lists 之前的文字里面简单的介绍了一些基本的东西,其中就涉及到了list的一点点的使用.当然,它 ...
- python for data analysis 2nd 读书笔记(一)
第一章相对简单,也么有什么需要记录的内容,主要用到的工具的简介及环境配置,粗略的过一下就行了.下面我们开始第二章的学习 CHAPTER 22.2Python Language Basics, IPyt ...
- Python开发 基礎知識 (未完代補)
一.Python基本知識 1.Python屬高階語言,所編築的是字節碼 2.一般狀態statement 終止於換行,如需使用多數行編寫,可在行末加上 \,以表延續 但在 parentheses ( ) ...
- [Python Essential Reference, Fourth Edition (2009)]读书笔记
Python programs are executed by an interpreter. When you use Python interactively, the special varia ...
- python 删除元组元素
#create a tuple tuplex = "w", "j" ,"c", "e" print(tuplex) #t ...
- 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 ...
随机推荐
- Java 以空格分割字符串
Java中使用类似于 str.split("/"); 的方法可以很方便的实现将一个字符串分割为数组, 但是如果分隔符是一个(或几个)空格呢?? 我们的本能反应或许应该是 str.s ...
- 中文版 ImageNet Classification with Deep Convolutional Neural Networks
ImageNet Classification with Deep Convolutional Neural Networks 摘要 我们训练了一个大型深度卷积神经网络来将ImageNet LSVRC ...
- 001.ActiveMQ概述
1. 概念 ActiveMQ是Apache推出的,一款开源的,完全支持JMS1.1和J2EE1.4规范的JMS Provider实现的消息中间件(Message Oriented Middleware ...
- 【参考】Linux下的Memcache安装
服务器端主要是安装memcache服务器端.下载:http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz另外,Memcache用到了lib ...
- Failed to connect to server
设置LR浏览器代理解决Failed to connect to server,Connection timed out问题. 虚拟机中,接口测试简单的Get请求,一直提示Failed to conne ...
- 连类比事-category和extension
extension看起来很像一个匿名的category,但是extension和有名字的category几乎完全是两个东西. extension在编译期决议,它就是类的一部分,在编译期和头文件里的@i ...
- 3ds Max绘制一个漂亮的青花瓷碗3D模型
这篇教程向小伙伴门介绍使用3ds Max绘制一个漂亮的青花瓷碗3D模型方法,教程很不错,很适合大家学习,推荐过来,一起来学习吧! 车削,材质贴图的应用,添加位图,渲染视图 步骤如下: 在桌面找到3DM ...
- JDOM,dom4j方式解析XML
<?xml version="1.0" encoding="UTF-8"?> <dataSources> <!-- 定义MySQL ...
- UI控件设置
去掉cesium默认的版权信息: 在style样式中添加 .cesium-widget-credits {display:none !important} 去掉动画控件.地址搜索控件.图层选择控件.操 ...
- Microsoft Visual Studio 2015打开TFS大量报错问题解决方案
用vs2015打开项目出现如图错误,尝试对XX项执行 添加 操作时遇到 XX 个错误,因为公司项目比较大,这个错误一直在弹,搜索了下,没有找到出现类似问题的解决方案. 因为这个路径是TFS(Team ...