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 ...
随机推荐
- HDU 2879
利用x<n的信息,可以证得当n为素数时,he[n]=2;同时,若n 为素数,则有HE[N^K]=2;因为若等式成立则有n|x(x-1).抓住这个证即可. 至于符合积性函数,想了很久也没想出来,看 ...
- CF 447B(DZY Loves Strings-贪心)
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 2016 ICPC CAMP Recording
等了好久终于等到今天 马上能和群巨们一起学习了 希望不要暴露我太弱的本质............ 北京不冷,就是风大~~~ 1.24 8点准时起床了,准备下楼吃早饭 (这个宾馆好多美美的空姐对面就是东 ...
- kibana智能检索发送多次_msearch —— 配置index pattern,同时设置时间段,就知道到底是在哪些索引里去查找数据了
kibanasite/elasticsearch/log-*/_field_stats?level=indices 返回: {"_shards":{"total ...
- TensorFlow训练MNIST报错ResourceExhaustedError
title: TensorFlow训练MNIST报错ResourceExhaustedError date: 2018-04-01 12:35:44 categories: deep learning ...
- BZOJ 4260 trie树
思路: 搞一个前缀异或和 一次从左往右 另一次从右往左 异或最大值 用字典树搞一搞 //By SiriusRen #include <cstdio> #include <cstrin ...
- js函数参数理解
eg: function setName(obj){ obj.name = "Nicholas"; obj = new Object(); obj.name = "Gre ...
- 接口测试工具篇--postman
上面是postman的主页面,可以输入接口url,设置请求方式(get或post) 下面主要讲一些其他接口测试需要用到的设置Authorization用来设置权限验证的,可以选择权限验证的方式 hea ...
- php 扩展 suhosin 配置不当引发的报错及其解决方法
1. /var/log/messages 频繁报错: Jul :: localhost suhosin[]: ALERT - script tried to increase memory_limit ...
- vuecli的使用之项目中的文件
cli创建的项目截图 node_moudule :下载的依赖包的存储位置. public :html的地方??? src :写代码的地方 man.js :入口文件 .browserslistrc :浏 ...