惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
U
Unit 42
The Register - Security
The Register - Security
S
Security Affairs
博客园 - 【当耐特】
Latest news
Latest news
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
C
Cisco Blogs
宝玉的分享
宝玉的分享
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
P
Privacy & Cybersecurity Law Blog
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Vulnerabilities – Threatpost
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
N
News and Events Feed by Topic
Recorded Future
Recorded Future
Scott Helme
Scott Helme
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hacker News: Front Page
J
Java Code Geeks
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
Attack and Defense Labs
Attack and Defense Labs

博客园 - YiYezc

Python的if语句 Python元组 Python列表操作 Python列表管理 Python字符串 Python变量 centos安装autossh bash相关 Linux的bash快捷键 Vim程序编辑器 Linux下光盘镜像生成和刻录 Linux文件系统备份dump Linux下文件压缩与打包 Linux挂载 Linux磁盘分区 Linux文件访问和日志 block、inode、superblock详解 Linux文件系统的详解 Linux的权限对于文件与目录的意义 命令与文件的查询 ctime, atime与mtime释疑 Linux下文件特殊权限 umask相关内容
Python列表元素管理
YiYezc · 2026-04-17 · via 博客园 - YiYezc

1.列表的引用是连续存储的,但列表元素本身不一定是连续。

2.列表索引[-1]指向列表的最后一个对象。

3.修改列表元素

#直接使用索引对相应元素进行修改

num=['one','two','three','four','five']

num[0]='ONE'

执行后:num=['NOE','two','three','four','five']

4.在列表中增加元素

①在列表末尾增加元素

num=['one','two','three','four','five']

num.append('six')

执行后:num=['one','two','three','four','five','six']

②在列表中插入元素

#在num[0]位置插入'zero'

num=['one','two','three','four','five']

num.insert(0,'zero') 

执行后:num=['zero','one','two','three','four','five']

注意方法插入中的参数索引与实际插入的位置关系

5.从列表中删除元素

①使用del删除

#删除num[1]元素

num=['one','two','three','four','five']

del num[1]

执行后:num=['one','three','four','five']

②使用pop( )方法删除元素

num=['one','two','three','four','five']

poped_num=num.pop( )

执行后:num=['one','three','four']

poped_num='five'

注意,方法pop( )默认是弹出最后一个元素,也可以通过索引指定删除某一个元素

num=['one','two','three','four','five']

poped_num=num.pop( 2)

执行后:num=['one','two','four','five']

poped_num='three'

③使用remove( )方法删除元素

remove( )方法是已知要删除的元素的值,不知道位置,只会删除第一个匹配的元素

num=['one','two','three','four','five']

num.remove ('three')

执行后:num=['one','two','four','five']