对list的操作

name_list = ["zhangsan","lisi","wangwu"]
# """
# 1.取值和索引
#list index out of range--列表索引超出范围
print(name_list[2])
#想确定数据的位置
print(name_list.index("lisi"))
# 2.修改 有索引法,还有切片法
name_list[1] = "李四"
print('索引法',name_list)
name_list[-1:-3:-1]=[1,2] # 切片的最后一项不会被取到  没被检索到,切进去的话不考虑步长切多少,若步长为负数的话,切进去的列表也是倒的
print('切片法大批修改源列表',name_list)
# 3.删除 remove 可以从列表中删除指定的数据
#name_list.remove("wangwu")
#name_list.pop(1) 删除元素的索引
# name_list.clear() 清空列表
# 4.增加
# append,insert,extend
name_list.append("王小二")
name_list.insert(1,"小美眉")
temp_list = ["孙悟空","猪八戒","沙悟净"]
name_list.extend(temp_list)
# """
print(name_list)
努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
原文地址:https://www.cnblogs.com/wkhzwmr/p/14945073.html