List是一种有序的集合,可以随时【添加】和【删除】其中的元素
1、 支持增删改查
2、 列表中的数据是可以变化的【数据项可以变化,内存地址不会改变】
3、 用[ ] 来表示列表类型,数据项之间用逗号来分割,注:数据项可以是任何类型的数据
4、 支持【索引】和【切片】来进行操作List是一种有序的集合,可以随时添加和删除其中的元素
实践操作
classmate=['echo','sam','may']
print(classmate)
输出结果为:[‘echo’, ‘sam’, ‘may’]
#查看列表的类型
classmate=['echo','sam','may']
print(type(classmate))
输出结果为:
#获取列表的个数
classmate=['echo','sam','may']
print(len(classmate))<class 'list'>
输出结果为:3
#列表的索引
list1=['red', 'green', 'blue', 'yellow', 'white', 'black']
print(list1[0])
print(list1[1])
输出结果为:
red
green
#列表的切片
list1=['red', 'green', 'blue', 'yellow', 'white', 'black']
print(list1[:4]) #从0开始取4个数字,即0\1\2\3
输出结果为:[‘red’, ‘green’, ‘blue’, ‘yellow’]