# ppop() # 删除列表里最后一位 L1 = [11,22,33,"alex","wusir",] L1.pop() print("结果:",L1) print("------- end --------") 结果: [11, 22, 33, 'alex'] ------- end --------
# ppop() # 在括号里可以输入索引位置,然后删除 L1 = [11,22,33,"alex","wusir",] L1.pop(3) print("结果:",L1) print("------- end --------") 结果: [11, 22, 33, 'wusir'] ------- end --------
# remove # 指定索引删除 L1 = [11,22,33,"alex","wusir",] L1.remove("alex") print("结果:",L1) print("------- end --------") 结果: [11, 22, 33, 'wusir'] ------- end --------
# remove # 指定索引删除(只删除找到的第一个索引) L1 = [11,22,33,"alex","wusir",11,] L1.remove(11) print("结果:",L1) print("------- end --------") 结果: [22, 33, 'alex', 'wusir', 11] ------- end --------
# del # del是python全局性的删除指令,可以删除任何东西。 L1 = [11,22,33,"alex","wusir",11,] del L1[1] print("结果:",L1) print("------- end --------") 结果: [11, 33, 'alex', 'wusir', 11] ------- end --------
# del # del是python全局性的删除指令,可以删除任何东西。 L1 = [11,22,33,"alex","wusir",11,] del L1 print("结果:",L1) print("------- end --------") # print("结果:",L1) #NameError: name 'L1' is not defined # 报错了,因为 L1 列表 已经被删除了。
# del # del 可以范围删除。 L1 = [11,22,33,"alex","wusir",11,] del L1[3:5] print("结果:",L1) print("------- end --------") 结果: [11, 22, 33, 11] ------- end --------