Python更新列表
2023-09-11 14:21:27 时间
Python更新列表:
使用索引下标进行更新:
# 修改列表的第 6 个元素为 d
lst = ['a','b','c',1,2,3]
lst[5] = 'd'
print(lst)
# ['a', 'b', 'c', 1, 2, 'd']
使用切片对列表进行更新:
# 修改列表的第2个元素到最后为 hey
lst = ['a','b','c',1,2]
lst[2:] = 'hey'
print(lst)
# ['a', 'b', 'h', 'e', 'y']
# 修改列表的第3个元素到第8个元素为 hello
lst = [1,2,3,'a','b','c','d','e',4,5,6]
lst[3:8] = 'hello'
print(lst)
# [1, 2, 3, 'h', 'e', 'l', 'l', 'o', 4, 5, 6]
使用 append 方法增加元素:
# 使用 append 方法对列表进行更新
lst = ['a','b','c',1,2,3]
lst.append('d')
print(lst)
# ['a', 'b', 'c', 1, 2, 3, 'd']
2020-02-09
相关文章
- Python脚本扫描给定网段的MAC地址表(scapy或 python-nmap)
- rebbitmq之python_pika监控远程连接及自动恢复(七)
- How to run python interactive in current file's directory in Visual Studio Code? Python路径问题
- python列表与数组的效率对比
- 快速上手python的简单web框架flask
- Python初学者如何系统的学习python————Python入门学习指南--内附学习路径
- Python零基础入门,2分钟带你了解python
- 使用python生成大量数据写入es数据库并查询操作2
- 最完整的自动化测试流程:Python编写执行测试用例及定时自动发送最新测试报告邮件
- gyp ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 【Python】【爬虫】IP代理/IP限制/IP被封/通过接口调用查询本机IP
- python图像处理库PIL的基本概念介绍
- python读取文件行号和内容的便捷方法
- python学习之基于Python的人脸识别技术学习
- 解决Python无法写入Mongodb数据仓库方法汇总
- 转 Python3 错误和异常/ Python学习之错误调试和测试
- Python Excel教程之如何将多个 excel 文件合并为一个文件(教程含源码)
- python之导入模块
- Python学习---django之admin简介
- Python学习---生成器的学习1210
- python中循环的技巧
- [Spark][Python]DataFrame where 操作例子
- 【Python】python扩展
- python assert的作用
- 2.1 The Python Interpreter(python解释器)
- [Python]B站学习笔记---列表(List)
- 电商 Python 淘宝主图下载 淘宝详情图下载 考拉海购主图下载
- 电商 Python 生成补单公司需要的评论格式
- python——numpy中的size()函数