python 列表list 电脑版发表于:2022/5/19 15:07 python 列表list ``` ''' list ''' ## 申明 list1 = ['a','m','c','g','b'] ## 访问 print(list1[2]) print(list1[-2]) print(list1[0:2]) print(list1[2:]) ## 修改 print("---------------------------") list1[2]="mm" print(list1[2]) ## 添加 list1.append("xx") print(list1[-1]) print(list1) ## 删除 del list1[2] list1.remove("a") print(list1) ## 判断某个元素是否包含在列表中 iscontent = 3 in [1,5,7] print(iscontent) ## 拿到list的长度 listlength = len(list1) print(listlength) ## 两个list之间相加 listsum = [1,5,7]+[2,4,8] print(listsum) ## 使用循环遍历list ### while i = 0 listsumlen = len(listsum) while i < listsumlen : print(listsum[i]) i=i+1 ### for循环 for item in listsum : print(item) ```