Python-list
来源:互联网 发布:淘宝商城怎么开店 编辑:程序博客网 时间:2024/06/07 10:15
列表是最常用的Python数据类型,在一个方括号内以逗号分隔。列表的数据项不需要有相同的数据类型。例如:
list1 = ['physics', 'chemistry', 1997, 2000]
访问列表中的值,可直接使用下标索引。例如:
print(list1[0])print(list2[2:5])
更新列表,可直接替换列表元素。例如:
list1[2]=2001
删除列表元素,可以使用del语句。例如:
del list1[2]
遍历整个列表,可以使用for循环。例如:
a = [1, 2, 3]for i in a: print(i)
列表切片,可以访问单个列表元素。例如:
a = [1, 2, 3, 4, 5, 6]print(a[:4]) #输出前4个元素,没有指定第一个索引,将自动从列表开头开始>>[1, 2, 3, 4]
简单列表的复制可以使用[:]。例如:
a = [1,2,3,4,5,4]b = a[:]print(b)>>[1, 2, 3, 4, 5, 4]
阅读全文
0 0
- Python List:
- python list
- python list
- python list
- Python.list
- Python list
- python list
- Python List
- Python List
- python list
- Python---list
- python-list
- python list
- python list
- python list
- Python List
- Python list
- python list
- ZooKeeper ZAB协议简述
- Spring中的ResourceLoader接口
- c#空合并运算符号的用法
- adminLTE 教程 -0 基础布局
- MySql 监控sql执行
- Python-list
- python 字符串格式化调用方法
- post 相比get 有很多优点,为什么现在的HTTP通信中大多数请求还是使用get
- PCB设计中的的3W规则和20H原则
- 异常
- hdu_2682_prime
- 2-8·crontab计划任务管理
- 根据图片路径,把图片转为byte数组
- Rhyme/Spring5.0.2.RELEASE官方英文文档学习笔记(1) Introduction to the Spring IoC container and beans