1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
| """ 这个主要进行list序列容器的学习 list容器的特点: 1.可以存储不同数据类型的数据 2.有序存储(记录存储的数据)、索引 3.数据可以重复 4.可以进行增删查改 """
list = []
list.append(1) list.append(2) list.append(3) list.append(4) list.append(5) print(list,type(list))
list.extend([6,7,8,9,10]) print(list,type(list))
list.insert(0,11) print(list,type(list))
list += ["hello","world"] print(list)
list *= 3 print(list)
list = ['odin', 'jack', 'lucy', 'andi', 'jame', 'peter'] del list[0] print(list) del list[-1] print(list) ele = list.pop(-3) print(ele) print(list) list.remove("andi") print(list)
list = ['odin', 'jack', 'lucy', 'andi', 'jame', 'peter'] list[2] = "merry" print(list)
print(len(list)) list.append("odin") list.append("odin") print(list.count("odin")) print(list[4], list[-4]) print(list) print(list.index("odin"))
for ele in list: print(f"{ele} ", end='') print()
list.clear() print(list)
""" 主要进行tuple序列(容器)的学习 作者:jack 日期:23.10.10
tuple容器的特点: 1、可以存储不同数据类型的数据 2、有序存储(记录存储的顺序)、索引[0,len-1] 3、数据可以重复 4、只能进行查询 """
t = ("关羽", "张飞", "刘备", "赵云", "刘备") print(t[0], t[-1]) print(len(t)) print(t.count("刘备")) print(t.index("刘备"))
t = ('a',) print(t, type(t))
""" 这里是dictionary字典容器 特点: 1.存储键值,key和value可以是任意类型,key不可以为字典 2.key可以访问value,不支持索引 3.key不能重复,不可以存储重复的数据 4.支持crud """
dic = {} dic["name"] = "jack" dic["age"] = 23 print(dic)
dic["age"] = 24 print(dic)
del dic["age"] print(dic)
print(dic["name"])
dic.clear()
dict = {} print(dict)
dict["python"] = 100 dict["java"] = 60 dict["js"] = 80 print(dict)
del dict["python"] print(dict) ele = dict.pop("js") print(ele,type(ele)) print(dict)
dict["python"] = 90 print(dict)
for key in dict: print(key, dict[key]) print()
for name in dict.keys(): print(f"{name}" ,end='') print()
for key,value in dict.items(): print(f"{key} = {value}" ,end=' ') print()
sum = 0 for value in dict.values(): sum += value print(f"{sum}")
dict.clear()
""" set的用法 特点: 1.可以存储不同数据类型 2.无序存储,不支持索引 3.删除只能用pop 4.不可以存储重复数据 5.支持crud """
s = set() print(s,type(set))
s.add(1) s.add(2) s.add(3) s.add(4) s.add(5) print(s,type(s)) set1 = {"hello","world"} print(set.union(set1)) print(s.difference(set1))
s.remove(2) print(s,type(s)) ele = s.pop() print(ele,type(ele))
for ele in s: print(f"{ele} ", end='') print()
s = {-1,-2,-3} print(s)
print(len(s))
for ele in s: print(f"{ele} ", end='') print()
print(sorted(s))
|