python学习之数据类型—元组tuple,,元组:tuple1、


元组:tuple

1、python四大不可变数据类型之一(int,str,tuple,bool)

2、以小括号包起来起来,如只有一个元素,需在尾部加一个逗号,因为不加的话,python可能认为其实一个变量或是做数学运算等

3、元组中的第一层数据不可变,如其第二层数据类型为可变数据类型(list,dict,set),其可变

4、元组可通过循环,切片等进行查询

5、元组是有序的

增:

??元组不可变,故无法增加元素

删:

?? 同上

改:

??同上

查:

索引和切片查询:

tuple_staudy = ("alter","china","upper","lower","iterable",[‘pycharm‘,‘file‘,‘edit‘,‘view‘])

tuple_staudy [3] ---->lower

tuple_staudy[1:5] ----->china,upper,lower,iterable

for 循环查找:

for i in tuple_staudy:

  print(i)

解构:

a,b = ("3","6")

print(a) a = 3

print(b) b = 6

注:左边元素个数必须和右边一致,同样的str,list,dict 都有这种特性

如 str , list ,tuple 公共方法 count(对象), len(对象) ,index(”元素“)

python学习之数据类型—元组tuple

评论关闭