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 ...
随机推荐
- iOS-AFNetworking3.0上传大量(1000张)图片到服务器
背景: 最近项目要做上传图片功能,图片必须是高清的,所以不让压缩,上传图片是大量的,比如几百张,这个如果是用afn,将图片直接for循环加入到formData里会出现一个问题,临时变量太多,导致内存紧 ...
- OPEN(SAP) UI5 学习入门系列之三:MVC (下) - 视图与控制器
继续来学习UI5的MVC模型吧,这次我们来探讨视图与控制器. 1 视图 在MVC中,视图用来定义和渲染UI.在UI5中,视图的类型是可以自定义的,除了以下预定义的四种视图类型之外,你也可以定制自己的视 ...
- countDown
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- BZOJ1113 Poi2008 海报PLA【单调栈】【水】
BZOJ1113 Poi2008 海报PLA Description N个矩形,排成一排. 现在希望用尽量少的矩形海报Cover住它们. Input 第一行给出数字N,代表有N个矩形.N在[1,250 ...
- 高度注意 Map 类集合 K/V 能不能存储 null 值的情况
集合类 Key Value Super 说明 Hashtable 不允许为 null 不允许为 null Dictionary 线程安全 ConcurrentHashMap 不允许为 null 不允许 ...
- 定义文档兼容性、让IE按指定版本解析我们的页面
http://blog.useasp.net/archive/2013/05/29/x-UA-compatible-defining-document-compatibility-emulate-ie ...
- 将 PCB 文件转换为可读的文本
将 PCB 文件转换为可读的文本 将元件转成列表. 坐标也放到列表中. 以元件号为排序. 使用 json 格式,并格式,方便对比. 元件网络转成单独文件. 特殊说明生成单独文件.
- oracle之 调整 I/O 相关的等待
I/O相关竞争等待简介 当Oracle数据库出现I/O相关的竞争等待的时候,一般来说都会引起Oracle数据库的性能低下,发现数据库存在I/O相关的竞争等待一般可以通过以下的三种方法来查看Oracle ...
- jdk1.8新特性应用之Collection
之前说了jdk1.8几个新特性,现在看下实战怎么玩,直接看代码: public List<MSG_ConMediaInfo> getConMediaInfoList(String live ...
- python笔试面试题_视频中(待完善)
一.选择填空题 1. 用一行代码交换a,b的值 a,b = 1,2 print(a,b) a,b = b,a print(a,b) 2. 元祖中有一个元素,有逗号则类型是元祖,无逗号则是远数据类型 t ...