标签:div 一个 loop app zhang -- clear each dir
1 # 1.append 2 a.append([9,8,7,6]) 3 print(a) 4 --[1, 2, 3, 4, 5, 6, [9, 8, 7, 6]] 5 6 # 2.insert 7 a.insert(7, 8) 8 print(a) 9 --[1, 2, 3, 4, 5, 6, [9, 8, 7, 6], 8] 10 11 # 3. extend 12 a.extend("zhang") 13 print(a) 14 --[1, 2, 3, 4, 5, 6, [9, 8, 7, 6], 8, ‘z‘, ‘h‘, ‘a‘, ‘n‘, ‘g‘] 15 16 # 4. + 17 a = a+[9] 18 print(a) 19 --[1, 2, 3, 4, 5, 6, [9, 8, 7, 6], 8, ‘z‘, ‘h‘, ‘a‘, ‘n‘, ‘g‘, 9]
a = [1, 2, 3, 4, 5, 6, 7, 8, 9] # 1.remove a.remove(3) print(a) --[1, 2, 4, 5, 6, 7, 8, 9] # 2.pop s = a.pop(1) print(s) print(a) --2 --[1, 4, 5, 6, 7, 8, 9] # 3. del del a[0:4:2] print(a) --[4, 6, 7, 8, 9] # 4. clear a.clear() print(a) --[]
直接利用 list[index] = object 修改,[index]可以按照切片的格式修改多个,切片的部分规则如下
a = [1, 2, 3, 4, 5, 6, 7, 8, 9] a[1:2] = "1", "2", "3" print(a) --[1, ‘1‘, ‘2‘, ‘3‘, 3, 4, 5, 6, 7, 8, 9] a[1:3] = "1", "2", "3" print(a) --[1, ‘1‘, ‘2‘, ‘3‘, ‘3‘, 3, 4, 5, 6, 7, 8, 9] a[1:4] = "1", "2" print(a) --[1, ‘1‘, ‘2‘, ‘3‘, 3, 4, 5, 6, 7, 8, 9] a[1:2] = "come on" print(a) --[1, ‘c‘, ‘o‘, ‘m‘, ‘e‘, ‘ ‘, ‘o‘, ‘n‘, ‘2‘, ‘3‘, 3, 4, 5, 6, 7, 8, 9]
标签:div 一个 loop app zhang -- clear each dir
原文地址:https://www.cnblogs.com/JackLi07/p/9852605.html