做百度网站哪家公司好,seo经验,牛推网官网,网上工商注册流程list1 [tom,cat,Lili]
print(list1[0].title())Tom#append()列表方法在列表末尾添加新元素
list1.append(233)
print(list1)
#可以先创建空列表#xff0c;再进行追加append(..)以添加[tom, cat, Lili, 233]#insert()列表方法插入元素
l…list1 [tom,cat,Lili]
print(list1[0].title())Tom#append()列表方法在列表末尾添加新元素
list1.append(233)
print(list1)
#可以先创建空列表再进行追加append(..)以添加[tom, cat, Lili, 233]#insert()列表方法插入元素
list1.insert(1,kate)
print(list1)[tom, kate, cat, Lili, 233]#del...语句删除元素注意这里是语句不是方法
del list1[2]
print(list1)[tom, kate, Lili, 233]#pop()列表方法删除(弹出)列表末尾的元素(对象)
poped_ele list1.pop()
print(fThe poped element is {poped_ele}!)
print(fThe current list1 is {list1})
#pop(n)可以从列表中部分弹出下标为n的元素
print(fThe 2th([1]) element kate will be poped,the result is {list1.pop(1)} )
The poped element is 233!
The current list1 is [tom, kate, Lili]
The 2th([1]) element kate will be poped,the result is kate print(fThe current list1 is {list1})The current list1 is [tom, Lili]#remove()列表方法根据值删除列表中的元素
list1.remove(tom)
print(fThe current list1 is {list1})The current list1 is [Lili]#sort()列表方法对列表进行默认永久排序升
list2 [d,a,c,b]
list2.sort()
print(fThe sorted list2 is {list2})
#reverse参数决定升降序True则降序The sorted list2 is [a, b, c, d]#sorted(listname)方法创建排序后的对象
list3 [d,a,c,b]
sorted_list3 sorted(list3)
print(sorted_list3)
sorted_list3_reverse sorted(list3,reverseTrue)
print(sorted_list3_reverse)[a, b, c, d]
[d, c, b, a]#reverse(listname)方法反转列表顺序(不进行排序)
#len(list)确定列表长度#4.操作列表#list()将range()的结果转化为列表
numbers list(range(1,6)) #[1,6)
print(numbers)[1, 2, 3, 4, 5]#min(listname),max(listname),sum(listname)对列表元素分别求最大最小与和
print(fmin:{min(numbers)} max:{max(numbers)} sum:{sum(numbers)})min:1 max:5 sum:15#切片
list5 list(range(1,6))
print(list5)
cut_list list5[0:3]
print(cut_list)[1, 2, 3, 4, 5]
[1, 2, 3]#复制列表(浅拷贝)
list6 list5[:]
print(list6)
print(id(list5) id(list6))[1, 2, 3, 4, 5]
False#元组元素不可变
dimensions (200,50)
print(f({dimensions[0]},{dimensions[1]}))
for dimension in dimensions:print(dimension)(200,50)
200
50#in 和 not in判断元素是否在集合中
print(200 in dimensions)
print(300 not in dimensions)True
True#字典键(字符串)值(任何对象)对集合
dic {color : yellow, score : 5,a : 3}
dic[score] 3 #键不能变值可以变且可添加减少
print(dic)
print(dic[color])
print(dic[score])
print(dic[a])
print(添加键值对:name:zhang san)
dic[name] zhang san
dic[name].title()
print(f添加后的字典是{dic})
#也能进行遍历
print(遍历dic)
for key,value in dic.items():print(fkey:{key} value:{value}){color: yellow, score: 3, a: 3}
yellow
3
3
添加键值对:name:zhang san
添加后的字典是{color: yellow, score: 3, a: 3, name: zhang san}
遍历dic
key:color value:yellow
key:score value:3
key:a value:3
key:name value:zhang san#del() 语句可以删除键值对
del dic[score]
print()#从字典中分离键值对创建键值列表items()方法可将字典生成列表(特殊列表只可用for拷贝后使用)
#key()/values()方法可将字典的键/值生成列表(特殊列表只可用for拷贝后使用)
keys []
values []
for key,value in dic.items():keys.append(key)values.append(value)pass
print(dic)
print(keys)
print(dic.keys())
print(dic.values())
print(values){color: yellow, a: 3, name: zhang san}
[color, a, name]
dict_keys([color, a, name])
dict_values([yellow, 3, zhang san])
[yellow, 3, zhang san]#set()函数可以将传入的列表/元组去掉重复项返回一个集合{...}
sets set(list([1,1,1,2,3,4]))
print(sets){1, 2, 3, 4}