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 ...
随机推荐
- jQuery扩展 模糊删除sessionStroage
$.extend({ removeStorageLike : function(name){ //模糊删除 for(var k in sessionStorage){ if(k.indexOf(nam ...
- Sublime Text 2 设置文件详解(转)
Sublime Text 2是那种让人会一眼就爱上的编辑器,不仅GUI让人眼前一亮,功能更是没的说,拓展性目前来说也完全够用了,网上介绍软件的文章和推荐插件的文章也不少,而且很不错,大家可以去找找自己 ...
- ffpmeg下rtmp踩坑记录
1. flash端发布直播流 2.在 ffplay 命令行中 播放rtmp 直播流 ffplay "rtmp://127.0.0.1:80/live/ss live=1" 一直出 ...
- 值类型struct在foreach中的陷阱
最近踩了一个坑,为了优化代码,把class改为了struct,结果发现原来的初始化语句没有预期的运行,伪代码如下: public struct A { bool _isActive; public v ...
- 每天一个linux命令:【转载】touch命令
linux的touch命令不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件. 1.命令格式: touch [选项]... 文件... 2.命令参数: -a ...
- POJ3696 The Windy's 【网络流】
#include<iostream> #include<vector> #include<cstring> #include<algorithm> #i ...
- SqlServer使用CONVERT 对时间进行格式化
前言 在最近使用SqlServer的时候遇到时间格式的转换,特此记录下. 本文参考:https://www.cnblogs.com/xiaoleiel/p/8301027.html,如有侵权,请联系删 ...
- for(j=0,i=0;j
for(j=0,i=0;j<6,i<10;j++,i++) { k=i+j; } k 值最后是多少? <script type="text/javascript" ...
- 接口测试框架——第四篇-url、excel内容等
到现在为止,发送邮件(email_module).读excel(excel_module).发送requests(requests_module).常量(setting)我们都已经完成了,看看第一篇中 ...
- CentOS编译安装php7.2
介绍: 久闻php7的速度以及性能那可是比php5系列的任何一版本都要快,具体性能有多好,建议还是先尝试下再说.如果你是升级或新安装,那你首先需要考虑php7和程序是否存在兼容性,如果程序是基于php ...