目录
python列表
变量可以存储一个元素,而列表是一个大容器,可以存储N多个元素,程序可以方便的对这些数据进行整体操作(可以存储多个不同的数据类型)
列表相当于其它语言的数组
正序索引 | 0 | 1 | 2 | 3 | 4 | 5 |
数据 | 'hello' | 'world' | 'python' | 34.7 | 1234 | 'sycyyds' |
倒序索引 | -6 | -5 | -4 | -3 | -2 | -1 |
lst = ['hello','world','python',98]
print(id(lst)) //查看标识
print(type(lst)) //查看数据类型
print(lst) //输出值
1.列表的创建与删除
列表中的元素放置在“[]”中,两个相邻的元素之间使用“,”隔开。同一个列表中的元素可以为任何类型的数据,如数值/字符串/列表等
列表的创建方式
1.使用中括号
2.调用内置函数list()
# 1. 使用[]
lst1 = ['hello','world',98]
# 2. 使用内置函数list()
lst2 = list(['hello','world',98])
print(lst1)
print(lst2)
列表的特点
1.列表元素按顺序有序排序
lst = ['hello','world','python',98]
print(lst)
2.索引映射唯一数据
正序索引 | 0 | 1 | 2 | 3 | 4 | 5 |
数据 | 'hello' |