坚持+思考+输出
1、学习方式:查看提供视频(30分钟)+自我整理笔记(2小时)+周末视频输出
2、笔记方式按提问方式整理。
# name = ["like","love","love","good"] # n2 = ["test","hebing"] #print(dir(name)) # 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort' #列表的增加操作 # name.append("插入最后") #添加到最后 # print(name) # # name.insert(1,"插入指定位置") # print(name) # # name.extend(n2)#把n2插入到name列表里面 # print(name) # # name.insert(2,[1,2,3]) #列表嵌套 # print(name) name = ["like","love","love","good"] # n2 = ["test","hebing"] #删除 # del name[0] #删除指定元素 # print(name) # # name.pop() #默认删除最后一个元素并返回被删除的值 # print(name) # # name.pop(1)#删除指定元素 # print(name) # # n2.clear() #直接删除 # print(n2) name.remove("like") #直接移出元素 print(name) # 查操作 # name = ["like","love","love","good","like"] # n2 = ["test","hebing"] # # print(name.index("love"))#返回从左开始匹配到的第一个like的索引 # # print(name.count("like")) #返回like的个数 #切片 # name = ["like","love","love","good","like"] # n2 = ["test","hebing"] # # print(name[1:7])# 切片的特性是顾头不顾尾,即start的元素会被包含,end-1是实际取出来的值 # # print(name[1:7:2])# 步长, 允许跳着取值 # # print(name[::-1])#通过把步长设置成负值,可达到列表返转的效果['like', 'good', 'love', 'love', 'like'] # 排序&反转 # 排序 a = [83,4,2,4,6,19,33,21] #从小到大进行排序 # a.sort() # print(a) # 反转 # a.reverse() # print(a) # print(a[::-1]) # 循环列表 name = ["like","love","love","good","like"] for i in name: print(i)