Ganso (tuple)
• Parentheses operator: ' () '
Role:
1, control operation priority (highest priority)
1+2*3 (1+2)*31+2**3 (1+2)**31 (1)表示1 一个数字加圆括号值与类型都不变
2, as an integral part of the GANSO (not required)
• Yuan zu
List:
元素:可以任意修改mutable,任意插入或者删除一个元素
Ganso
元素:不可以修改 immutable,元祖本身不可以改变·创建一个元祖
1, the basic creation of a meta-ancestor
t=(1,2,3,4,5)
2. Visit a meta-ancestor
t[0]#访问下标0的元素
3, Ganso of the Shard
同列表一样t[0:3] #取前3个值t[:3]#取前三个元素t2=t[:] #拷贝元祖,并且让t2指向新的元祖
4, Ganso can not be modified
l=[1,2,3,4,5]t=(1,2,3,4,5)print t[0]# 报错not support assignmentprint l[0]#正常不会报错
5. When Yongzu has only one element
t=(10,) 不加逗号就是整数
6. Create a meta-ancestor without parentheses
t=10,与t=(10,)效果一样t=10,20,30,40也是一个元祖
The print function adds a brace element ancestor
print 1,2,3,4#输出四个值print (1,2,3,4)#输出元祖t=(1,2,3,4)print t
7, empty Yuan zu
t=()print tt=(,)#语法错误
If there is an element in the tuple, the comma is used to distinguish whether it is ganso, and there are no elements, and parentheses distinguish whether the progenitor
8. Multiplication operation
t=(1,2,3)t2=t*3print t2
* List and meta-progenitor multiplication are converted to multiple lists with Ganso addition
• Updates to Ganso
(1,2,3)在1后面插入4,可以这样操作t=(1,2,3) #创建一个元祖,t1=t[0:1]#通过分片截取拷贝之前的内容t2=t[1:]#通过分片截取后面的内容t3=t1+(4,)+t2 #(1,2,3,4),将两个截取的数据进行相加拼接t=t3 #拼接数据重新赋值t3指向的元祖用t也指向分片:把原元祖通过下标截取一段数据,并且拷贝出来以前的旧元祖从来没有发生改变
• Deletion of Ganso
del直接删除t=(1,2,3)del t
Delete the entire meta-ancestor, exactly is delete the meta-ancestor's label (variable name) and the Ganso data itself is not
is deleted, when there are multiple labels pointing at a single ancestor, the variable name is deleted one by one, and the meta-ancestor itself is still there.
Data that is not pointed to will be recycled as garbage.
• Meta-ancestor related operators
1, Ganso splicing operator:
t1=(1,2,3)t2=(4,5,6)t=t1+t2
2. Repeat operator: ' * '
t=(1,2,3)t1=t*3#(1,2,3,1,2,3,1,2,3)
3. Relational operators:
< > <= >=t1=(1,2,3)
T2= (4,5,6)
Print T1<t2
True
The first one compares the back again.
4. Logical operator:
and or not
5. Member Operators:
in /not in t1=(1,2,3)print 1 in t1True
Python--007--Ganso