Python data type-list (list)

  1. List (list) is an ordered collection, you can add and delete its elements at any time;
  2. The elements of the list can be different;
  3. The list also supports slicing, and the interception syntax is as follows:

    Variable [start subscript: end subscript: step]

  4. 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的元素

Guess you like

Origin blog.csdn.net/weixin_42961082/article/details/111492854