List是一种有序的集合,可以随时【添加】和【删除】其中的元素

1、 支持增删改查
2、 列表中的数据是可以变化的【数据项可以变化,内存地址不会改变】
3、 用[ ] 来表示列表类型,数据项之间用逗号来分割,注:数据项可以是任何类型的数据
4、 支持【索引】和【切片】来进行操作List是一种有序的集合,可以随时添加和删除其中的元素

实践操作

  1. classmate=['echo','sam','may']
  2. print(classmate)

输出结果为:[‘echo’, ‘sam’, ‘may’]

  1. #查看列表的类型
  2. classmate=['echo','sam','may']
  3. print(type(classmate))

输出结果为:

  1. #获取列表的个数
  2. classmate=['echo','sam','may']
  3. print(len(classmate))<class 'list'>

输出结果为:3

  1. #列表的索引
  2. list1=['red', 'green', 'blue', 'yellow', 'white', 'black']
  3. print(list1[0])
  4. print(list1[1])

输出结果为:
red
green

  1. #列表的切片
  2. list1=['red', 'green', 'blue', 'yellow', 'white', 'black']
  3. print(list1[:4]) #从0开始取4个数字,即0\1\2\3

输出结果为:[‘red’, ‘green’, ‘blue’, ‘yellow’]