列表:
容器数据类型:列表:list 元组 tuple 字典 dict
集合 set 字符串 str
list中的元素可以是任何对象
列表内容更改(mutable)附加(append,extend)插入(insert)删除(remove,pop)
append只能添加一个元素,expend可以添加列表
insert是在指定位置添加元素 remove移除指定元素
pop删除指定位置的元素
两个列表直接相等是直接为相同的存储位置,修改一个另一个也会改变。浅拷贝的话就不会这样。
count统计某个元素出现的次数 index寻找指定元素第一次出现的位置 reverse反转列表 sort排序列表
练习题:
1.
lst=[2,5,6,7,8,9,2,9,9]
lst.append(15)
lst.insert(5,20)
lst.extend([2,5,6])
lst.pop(3)
lst.reverse()
lst.sort()
lst.sort(reverse=True)
lst=[1,[4,6],True]
lst[0]*=2
lst[1][0]*=2
lst[1][1]*=2
list1=[1,2,4,6,4,5]
a=len(list1)
times=0
for i in range(1,a-1):
list2=list1[0:i+1]
list3=list1[i:a]
list4=sorted(list2)
list5=sorted(list3,reverse=True)
if list2==list4 and list3==list5:
print(i)
print("True")
times+=1
break
if times==0:
print("False")
心得:加油,今天完成的太晚了,就瞎写了。 ? - ?