List列表是一个有序且可变的集合。允许重复成员。
turple元组是一个有序且不可更改的集合。允许重复成员。
Set集合是一个无序且无索引的集合。没有重复的成员。
dict字典是一个有序*且可变的集合。没有重复的成员。
!!!从 Python 3.7 版开始,字典才是有序的!!
2 列表类型(序列)
mylist = ["一号", "二号", "三号"]
print(mylist)
mylist2=list["一号", "二号", "三号"]
print(mylist2)
mylist3 = ["一号", "四号", "三号","9号"]
print(mylist3)
print(mylist[0])
print(mylist[-2])
print(mylist3[0:2]) #2不在内
print(mylist3[-2:-1])
for i in mylist :
print(i)
for i in range(len(mylist)):
print([i])
i =0
while i < len(mylist):
print(mylist[i])
i+=1
print(len(mylist))
print('四' in mylist3)
if '四号' in mylist3:
print("数据存在")
mylist3[0]='五号啦'
print(mylist3)
mylist3[0:3]=['6号啦','对得了']
print(mylist3)
mylist4 = ["一号", "四号", "三2号","10号",'888']
mylist4.insert(1,'cahrule')
print(mylist4)
mylist4.append("moweitianj")
print(mylist4)
mylist4.extend(mylist3)
mylist5 = ["一号", "四号", "三9号","10号",'8998']
mylist5.remove('一号')
print(mylist5)
mylist5.pop(2)
print(mylist5)
del mylist5[0]
print(mylist5)
del mylist5
print(mylist5) #数据列表不存在
mylist6 = ["一号", "四号", "三9号","10号",'8998']
mylist6.clear()
print(mylist6)
mylist8= ["ABH", "aboh", "sudi","13号",'234']
mylist8.sort()
print(mylist8)
mylist8.sort(key=str.lower)
print(mylist8)
mylist8.reverse()
print(mylist8)
mcopylist=mylist8.copy()
mylisys=list(mylist8)
print(mcopylist)
print(mylisys)
3 字典类型
my_tuple=(1,2,5,7)
print(my_tuple)
my_blank=()
my_blank2=tuple()
print(type(my_blank2),my_blank2)
my_tuples=1,2,3,88
print(type(my_tuples),my_tuples)
my_tuple1=(1,)
my_tuple2=(1)
print(type(my_tuple1),my_tuple1)
print(type(my_tuple2),my_tuple2)
my_tuple3=((1,3),(5,6)) #多维组遍历出来展示
for i in my_tuple3:
print(i)
for i in my_tuple3: #列表数据遍历循环出来展示
for cs in i:
print(cs)
my_tuple5=(1,2,5,7,9,3)
print(my_tuple5[0])
print(my_tuple5[0:3])
print(my_tuple5[-3:-2])
str='好的'
mytuple=tuple(str)
print(type(mytuple))
print(max(my_tuple5))
print(min(my_tuple5))
print(my_tuple5.index(1))
print(my_tuple5.count(3))