Python处理多层镶套列表方法

使用”isinstance”区分处理多层列镶套列表.例子:

elvis = ["www","secret","elvis","chan",["Oh",["yes","like"],"love"]]
for list_elvis in elvis:
    if isinstance(list_elvis,list):
        for list2_elvis in list_elvis:
            if isinstance(list2_elvis,list):
                for list3_elvis in list2_elvis:
                    print(list3_elvis)
            else:
                print(list2_elvis)
    else:
        print(list_elvis)

以上记录爱维C文章Python处理多层镶套列表方法的内容…

Python的for循环

简单定义一个列表.

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

for循环的写法”for 目标标识符 in 列表:”例子:

elvis = ["www","secret","elvis","chan"]
for list_elvis in elvis:
    print(list_elvis)

以上记录爱维C文章Python的for循环的内容…

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简单列表记录的内容…