python笔记二
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python笔记二相关的知识,希望对你有一定的参考价值。
list学习
----------list :append 尾部插入----------
name_list = ["alex","tony","eirc"]
name_list.append(‘seven‘)
name_list.append(‘moon‘)
print(name_list)
----------list :insert 按位置插入----------
name_list = ["alex","tony","eirc"]
name_list.insert(2,‘pepole‘)
print(name_list)
----------list :extend 字符串扩展----------
name_list = ["alex","tony","eirc"]
temp = [11,22,33,44]
name_list.extend(temp)
print(name_list)
----------list :count 元素出现的次数----------
name_list = ["alex","tony","eirc"]
print(name_list.count(‘tony‘))
----------list :index 查找元素索引位置----------
name_list = ["alex","tony","eirc"]
print(name_list.index(‘alex‘))
----------list :pop 在原列表中移除最后一个元素,并将其赋值给别的变量----------
name_list = ["alex","tony","eirc"]
x = name_list.pop()
print(name_list)
print(x)
----------list :remove 移除某个元素----------
name_list = ["alex","tony","eirc"]
name_list.remove(‘alex‘)
print(name_list)
----------list :元素删除,删除指定索引位置----------
name_list = ["alex","tony","eirc"]
del name_list[1:3]
print(name_list)
以上是关于python笔记二的主要内容,如果未能解决你的问题,请参考以下文章