定义:有序可更改的集合,用方括号[ ]编写
创建列表:
List = ['a','b','c','d','e','f']
1. 访问列表(通过索引访问)
(1)从前往后索引,第一项索引为0
print(List [1])
-> b
(2)-1代表从后往前索引
print(List [-1])
->f
(3)指定范围[2:5] #索引从2开始到5,不包含5
print(List [2:5])
->c,d,e
2.更改项目值,使用索引号
List[1]="g"
print(List )
-> ['a','g','c','d','e','f']
3.遍历列表:for循环遍历列表
List = ['a','b','c','d','e','f']
for i in list:
print(i)