Python Tuples
1. basic
Tuples is a sequence of immutable object. It's a sequence, just like List. However, it cannot be changed.
- a = (1,2,3)
If a tuples only contain a object, we still need to include a comma.
- b = (1,)
2. accessing the value
- b = (1,2,3,4,5)
- b[0] #b[0] == 1
- b[1:3] #b[1:3] == (2,3)
3. Update the tuples
We can not change any value in a tuple.
- b = (1,2)
- b[0] = 3 #this is wrong
- #What we can do it's just
- a = (3,4)
- c = a+b
- #result (3,4,1,2)
4. delete a tuples
Since wen can not change a value in a tuple. What we can do is to delete a whole tuples.
- b = (1,2)
- del b
5. Basic operation
- b = (1,2)
- len(b) #return the length of b
- (1)*4 #(1,1,1,1)
- 1 in b #return Ture
- for i in b:
- print(i)
6. Built-in function
- cmp(tuples1, tuples2) #compare two tuples
- len(tuples)
- max(tuples1)
- min(tuples1)
- tuple(seq) #turn a seq into a tuple
Python Tuples的更多相关文章
- Python Learning - Two
1. Built-in Modules and Functions 1) Function def greeting(name): print("Hello,", name) g ...
- PyOpenGL利用文泉驿正黑字体显示中文字体
摘要:在NeHe的OpenGL教程第43课源代码基础上,调用文泉驿正黑字体实现中文字体的显示 在OpenGL中显示汉字一直是个麻烦的事情,很多中文书籍的文抄公乐此不疲地介绍各种方法及其在windows ...
- Python 系列:1 - Tuples and Sequences
5.3 Tuples and Sequences We saw that lists and strings have many common properties, e.g., indexing a ...
- 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] 03 - Lists, Dictionaries, Tuples, Set
Lists 列表 一.基础知识 定义 >>> sList = list("hello") >>> sList ['h', 'e', 'l', ' ...
- python常用序列list、tuples及矩阵库numpy的使用
近期开始学习python机器学习的相关知识,为了使后续学习中避免编程遇到的基础问题,对python数组以及矩阵库numpy的使用进行总结,以此来加深和巩固自己以前所学的知识. Section One: ...
- Python strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的
在python中,strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的对象. a = 1 def fun(a): a = 2 fun(a ...
- python arguments *args and **args ** is for dictionaries, * is for lists or tuples.
below is a good answer for this question , so I copy on here for some people need it By the way, the ...
- HackerRank-Python攻城歷程-1.Tuples
Solution: if __name__ == '__main__': n = int(input()) integer_list = map(int, input().split()) t=tup ...
随机推荐
- 《Unity 3D游戏客户端基础框架》系统设计
引言 最近到看一个 <贪吃蛇大战开发实例>,其中 贪吃蛇大作战游戏开发实战(3):系统构架设计 提供的系统架构的设计思路我觉得还是值得学习一下的,接下来的内容是我看完视频后的一点笔记. 架 ...
- 敏捷BI与数据驱动机制
大数据这件事,整体上还是说的多一些,做的稍微少一点.大数据可以是荒凉高原上波澜壮阔的机房,也可以润物细无声般融入到日常生活和工作.换句话说,大数据应该是一种文化. 在个人层面,很多人对数字和计算并不敏 ...
- python 多维list声明时的小问题
a=[[]]*3 a Out[18]: [[], [], []] a[0].append(1) a Out[20]: [[1], [1], [1]] b=[[] for _ in range(3)] ...
- keras 报错 ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(5001, 128), dtype=float32)'
在服务器上训练并保存模型,复制到本地之后load_model()报错: ValueError: Tensor conversion requested dtype int32 for Tensor w ...
- Python3 移动文件——合集
文件/文件夹操作头文件 import os import shutil 参考 Python3批量移动指定文件到指定文件夹
- 【剑指offer-25】合并两个单调递增的链表,C++实现(链表)
原创博客,转载请注明出处! 1.题目 输入两个单调递增的链表,输出两个链表合成后的链表(单调不减). 2.思路(递归) # 鲁棒性: 如果链表1是空链表,则直接输出链表2. 如果链表2是空链表,则直接 ...
- 10day1
但愿复赛的时候旁边坐的不是学军镇海杭二绍一的众神犇. 阅览室 模拟 [问题描述] 一个阅览室每天都要接待大批读者.阅览室开门时间是 0,关门时间是 T.每位读者的到达时间都 不一样,并且想要阅读的 ...
- bzoj 4447 小凸解密码
bzoj 4447 小凸解密码 先将原始状态的 \(B\) 处理出来,可以发现,若不修改,则每次指定的起始位置不同,对这个环 \(B\) 带来的影响只有 \(B_0\) 不同,即每次 \(B_0=A_ ...
- CF1109B Sasha and One More Name
CF1109B Sasha and One More Name 构造类题目.仔细看样例解释能发现点东西? 结论:答案只可能是 \(Impossible,1,2\) . \(Impossible:\) ...
- mysql 查找除id外其他重复的字段数据
如表 test1 有多个重复的字段 其中有些数据完全重复是错误的数据,我们要把他找出来,然后删除掉 select * from test1 a where (a.phone,a.name) in ( ...