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的更多相关文章

  1. Python Learning - Two

    1.  Built-in Modules and Functions 1) Function def greeting(name): print("Hello,", name) g ...

  2. PyOpenGL利用文泉驿正黑字体显示中文字体

    摘要:在NeHe的OpenGL教程第43课源代码基础上,调用文泉驿正黑字体实现中文字体的显示 在OpenGL中显示汉字一直是个麻烦的事情,很多中文书籍的文抄公乐此不疲地介绍各种方法及其在windows ...

  3. Python 系列:1 - Tuples and Sequences

    5.3 Tuples and Sequences We saw that lists and strings have many common properties, e.g., indexing a ...

  4. 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 ...

  5. [Python] 03 - Lists, Dictionaries, Tuples, Set

    Lists 列表 一.基础知识 定义 >>> sList = list("hello") >>> sList ['h', 'e', 'l', ' ...

  6. python常用序列list、tuples及矩阵库numpy的使用

    近期开始学习python机器学习的相关知识,为了使后续学习中避免编程遇到的基础问题,对python数组以及矩阵库numpy的使用进行总结,以此来加深和巩固自己以前所学的知识. Section One: ...

  7. Python strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的

    在python中,strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的对象. a = 1 def fun(a):     a = 2 fun(a ...

  8. 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 ...

  9. HackerRank-Python攻城歷程-1.Tuples

    Solution: if __name__ == '__main__': n = int(input()) integer_list = map(int, input().split()) t=tup ...

随机推荐

  1. JMter请求参数中文显示乱码

    如上图所示,上传的参数为中文的时候,显示不出来,解决方法如下: 1.进入Jmter安装文件bin文件夹,找到文件jmeter.properties 2.在该文件找到jsyntaxtextarea.fo ...

  2. ranch分析学习(四)

    经过的前面的梳理,整个ranch框架的结构,大致有了一个清晰的脉络,即使我说的不是很清楚大家也基本能阅读懂源码.下面我继续分析剩下的的几个文件. 7.ranch_transport.erl 这个文件是 ...

  3. C++题目(论述类)

    0.面向对象 三大特性:封装性.继承性.多态性 1.static  ①只进行一次初始化,而且保存在静态存储区,是在程序运行时就进行初始化了: ②当我们同时编译多个源文件(.c文件)时,所有未加stat ...

  4. request接收表单提交数据及其中文参数乱码问题

    一.request接收表单提交数据: getParameter(String)方法(常用) getParameterValues(String name)方法(常用) getParameterMap( ...

  5. 重温CLR(十一) 枚举类型、位标志和数组

    枚举类型 枚举类型(enumerated types)定义了一组"符号名称/值"配对.例如,以下Color类型定义了一组符号,每个符号都标识一种颜色: internal enum ...

  6. ubuntu换系统下载路径源

    ubuntn默认下载路径的源是国外的下载很慢换成国内的下载路径会好很多 在ubuntu应用搜索框(左上脚那个)中输入software 1.software&Updates 应用点击softwa ...

  7. cell的循环利用

    方式1 // 1.先根据cell的标识去缓存池中查找可循环利用的cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdent ...

  8. WPF绘制简单常用的Path(转)

    写代码出身的我们经常需要使用一些简单 但是不是规则图形的Path 但限于美工功底有限 不知道怎么去画 下面我告诉大家一些简单的小技巧 用代码来画Path 个人还是比较喜欢用代码 因为数值控制的更精细 ...

  9. luarocks 安装

    1. linux 安装 wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz tar zxpf luarocks-2.4.1.tar.gz ...

  10. cocos2d-x 3.2 关闭按钮点击立马销毁自己报错

    cocos2d-x 3.2 Button点击事件里调用移除当前层报错 http://www.th7.cn/program/ios/201408/271227.shtml 诡异的错误,点击关闭按钮,居然 ...