Python简单列表记录

简单定义一个列表.

elvis = ["www","secret","elvis","chan"]
print(elvis)

第一个数组是0开始.

查看一个列表有多少个元素使用”len”例子:

elvis = ["www","secret","elvis","chan"]
print(len(elvis))
print(elvis)

查看一个列表第几位元素是什么:

elvis = ["www","secret","elvis","chan"]
print(elvis[1])
print(elvis)

在结尾增加一个元素使用”append”例子:

elvis = ["www","secret","elvis","chan"]
elvis.append(".")
print(elvis)

在结尾增加一个元素集合使用”extend”例子:

elvis = ["www","secret","elvis","chan"]
elvis.extend([".","yes","."])
print(elvis)

删除特定元素使用”remove”例子:

elvis = ["www","secret","elvis","chan"]
elvis.remove("secret")
print(elvis)

在特定元素前面增加元素使用”insert”例子:

elvis = ["www","secret","elvis","chan"]
elvis.insert(1,"love")
print(elvis)

以上记录爱维C文章Python简单列表记录的内容…