💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
#### append ~~~ 增 list.append(3) ~~~ #### del 删 ~~~ del list[0] ~~~ #### clear ``` 清空 list.clear() ``` #### copy ``` 复制 a = [1, 2, 3] b = a b[0] = 5 # a现在是[5, 2, 3] ``` #### count ``` 计算指定元素在列表中出现的次数 str = [1, 2, 3, 4, 2, 1, 4] print(str.count(1)) # 2 ``` #### extend ~~~ a = [1, 2, 3] b = [4, 5, 6] c = a + b # 产生一个新的list print(a, b, c) # [1, 2, 3] [4, 5, 6] [1, 2, 3, 4, 5, 6] print(type(a), type(b), type(c)) print(id(a), id(b), id(c)) # 30237320 30237384 30854984 a = [1, 2, 3] b = [4, 5, 6] print(id(a)) # 34713736 a.extend(b) # 不产生新的list print(a, b) print(type(a), type(b)) print(id(a), id((b))) # 34713736 33710728 ~~~