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. BeautifulSoup的安装和使用

    Python用做数据处理还是相当不错的,如果你想要做爬虫,python是很好的选择,它有很多已经写好的类包,只要调用,即可完成很多复杂的功能,此文中所有的功能都是基于BeautifulSoup这个包. ...

  2. OPEN(SAP) UI5 学习入门系列之二: 最佳实践练习(上)

    这篇博文难产了很久,原来是打算一周更新一篇的,上周原计划写MVC,但是写了一半,发现带入了太多的细节,不太符合这个入门系列的主题. 当我们学习一个新的技能的时候,如果一开始就面对大量的细节,很容易陷入 ...

  3. 音乐随想——斯美塔那—G小调钢琴协奏曲

    乐源 Music -> Piano Trio -> Smetana:Piano Trioin G minor Op.15 总结 每一乐章都会有一段美到极致的主旋律. 第一乐章 起头即有凄凉 ...

  4. Git详解之七 自定义Git

    以下内容转载自:http://www.open-open.com/lib/view/open1328070404827.html自定义 Git 到目前为止,我阐述了 Git 基本的运作机制和使用方式, ...

  5. [转载][QT][SQL]sql学习记录4_sqlite约束

    转载自:定义以及示例请见 : http://www.runoob.com/sqlite/sqlite-constraints.html SQLite 约束 约束是在表的数据列上强制执行的规则.这些是用 ...

  6. 【paper】KDD15 - Interpreting Advertiser Intent in Sponsored Search

    Interpreting Advertiser Intent in Sponsored Search   主要内容是搜索广告的相关性预估模型,使用learning to rank的方法.亮点在于使用了 ...

  7. Spring配置--Aop配置详情

    首先我们来看一下官方文档所给我们的关于AOP的一些概念性词语的解释: 切面(Aspect):一个关注点的模块化,这个关注点可能会横切多个对象.事务管理是J2EE应用中一个关于横切关注点的很好的例子.在 ...

  8. BZOJ4033 HAOI2015 树上染色 【树上背包】

    BZOJ4033 HAOI2015 树上染色 Description 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并将其他的N-K个点染成白 ...

  9. BZOJ2330 SCOI2011 糖果 【差分约束】

    BZOJ2330 SCOI2011 糖果 Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一 ...

  10. 【spring源码学习】spring的aop目标对象中进行自我调用,且需要实施相应的事务定义的解决方案

    转载:http://www.iteye.com/topic/1122740 1.预备知识 aop概念请参考[http://www.iteye.com/topic/1122401]和[http://ji ...