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. 地图API的选择和使用

    在我们程序员的日常开发中,总会时不时的需要用到地图开发,我也在多次碰到之后,写下我对地图开发的理解经验和总结. 一.地图的选择 回想一下我们生活中用到的地图工具,数了一下,百度地图,高德地图,腾讯地图 ...

  2. iOS通讯录相关知识-浅析

    本文来自于:贞娃儿的博客  http://blog.sina.com.cn/zhenwawaer  在开发一些应用中,我们如果需要iPhone设备中的通讯录信息.或者,需要开发通讯录相关的一些功能.那 ...

  3. I.MX6 修改调试串口号(ttymx0 -> ttymxc2)

    I.MX6 修改调试串口号(ttymx0 -> ttymxc2) 一.参考文章: uboot修改默认调试串口ttymxc0 ->ttymxc4(imx53) http://www.xueb ...

  4. vue之element-ui设置全局弹出框

    这样的需求,在主要功能完成后,需要进行交互效果的完善,需要给请求api的时候添加一个加载中的一个弹出框.但是每个页面每个页面过的话,会很费时间和精力,这里我们可以采用element-ui中的服务式弹出 ...

  5. vue-cli搭建及项目目录结构

    今天总结一下vue的脚手架的搭建.很简单,今天我们就来说一下 一.vue 脚手架的搭建. 对于脚手架的具体搭建方法,我这里不在很详细的书写,具体方法我推荐菜鸟教程的方法,和具体,你一步一步的来就可以实 ...

  6. 【备份】 解决acer v5 471g arch关机后自动重启的问题

    Fedora 17 on an Aspire V5-571 -- Reboot on Shutdown13 FEBRUARY 2015Update on 2/13/15: This article w ...

  7. Flask第六篇——项目配置文件

    我们在开发中,通常将一些需要用到的配置选项单独放在一个文件中,比如叫configs.py中.然后通过一些方式加载. 现在将加载配置文件的方法罗列如下: 1.先新建文件configs.py,文件代码: ...

  8. Flask第二篇——服务器相关

    web服务器.应用服务器和web应用框架 web服务器:负责处理http请求.响应静态文件,常见的有Apache,Nginx以及微软的IIS 应用服务器:负责处理逻辑的服务器.比如php.python ...

  9. drone 学习四 几个有用的命令

    1. 安装cli 工具 linux curl -L https://github.com/drone/drone-cli/releases/download/v0.8.5/drone_linux_am ...

  10. js各种效果

    1.JavaScript 仿LightBox内容显示效果 2.固定高度的div,竖直方向出现滚动条,水平方向固定 http://www.jb51.net/css/109928.html <!do ...