- List (list) is an ordered collection, you can add and delete its elements at any time;
- The elements of the list can be different;
- The list also supports slicing, and the interception syntax is as follows:
Variable [start subscript: end subscript: step]
- The list format ['yh','micheal','jack'] is enclosed by [], and the elements in the brackets are separated by commas
The index value starts from 0, and -1 represents the end.
Use (+) to connect two lists, (*) is a repeated operation
classmates=['yh','xiaobai','xiaoming'] #创建列表
type(classmates) #类型
list
len(classmates) # 返回列表长度
3
classmates[1] # 方位列表元素
xiaobai
classmates.append('xiaohong') # 列表中追加元素
classmates.insert(1,'ww') # 向列表中指定位置插入
classmates.pop() # 默认删除列表中最后一位
classmates.pop(1) # 删除列表中指定位置元素
classmates[2]='xiaogou' # 覆盖列表中索引2的元素