names = [‘old_driver‘,‘rain‘,‘jack‘,‘shanshan‘,‘peiqi‘,‘black_girl‘] #创建一个空列表,添加元素 names.insert(-1,‘alex‘) #在black_girl 前插入一个 alex print(names) names[3] = ‘姗姗‘ #把shanshan改成中文 print(names) names2 = [‘oldboy‘,‘oldgirl‘] #在names列表中插入列表[‘oldboy‘,‘oldgirl‘] names.insert(2,names2) print(names) print(names.index(‘peiqi‘)) #返回peiqi的索引值 number = [1,2,3,4,5,6,2] #创建新列表,并把列表合并到names names.extend(number) print(names) print(names[4:7]) #取出names列表中4-7的元素 print(names[2:10:2]) #取出names2-10的元素,步长为2 print(names[-3:]) #取出names列表中最后三个元素 # for i in names: # print(names.index(i),i) #打印出每个元素的索引值和元素 # count = 0 # for i in names: # print(count,i) # count += 1 # for i in enumerate(names): #枚举 # print(i) # for index, i in enumerate(names): # print(i) # for i in names: #自己写的,想不出来,错的 # if names.index(i)%2 == 0: # names[i] = -1 # print(names.index(i), i ) # print(names) # for index, i in enumerate(names): # if index%2 ==0: #是否为偶数,%是整除 # names[index] = -1 # print(index,i) # print(names)