博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python Tuples
阅读量:6855 次
发布时间:2019-06-26

本文共 864 字,大约阅读时间需要 2 分钟。

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] == 1b[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 justa = (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 Turefor i in b:	print(i)

  

6. Built-in function

cmp(tuples1, tuples2) #compare two tupleslen(tuples)max(tuples1)min(tuples1)tuple(seq) #turn a seq into a tuple

 

转载于:https://www.cnblogs.com/KennyRom/p/6291960.html

你可能感兴趣的文章
Android studio 将 Module 打包成 Jar 包
查看>>
coffee script
查看>>
正则表达式大全
查看>>
SVN switch 用法详解
查看>>
Javascript文件下载顺序问题
查看>>
程序员第一定律:关于技能与收入
查看>>
网络通讯合并数据发送的重要性和实现原理
查看>>
Jquery getJSON 实现跨域请求 --- callback
查看>>
Zend Studio (eclipse)使用速度优化
查看>>
Linux系统各个目录的一般作用
查看>>
maven安装与配置
查看>>
Windows Phone 8 开发环境配置(记录)
查看>>
MVC
查看>>
使用重置按钮,重置表单信息
查看>>
在指定时间干,必须干(kbmmw 中的事件调度)
查看>>
通过微信查找SAP TCODE代码
查看>>
c 二叉树的使用
查看>>
Helpers\Assets
查看>>
Thrift安装问题
查看>>
Linux常用命令大全
查看>>