有以下几种方法来添加元素到一个list中:
my_list = [1, 2, 3]
my_list.append(4)
print(my_list) # 输出 [1, 2, 3, 4]
my_list = [1, 2, 3]
my_list.insert(1, 5)
print(my_list) # 输出 [1, 5, 2, 3]
my_list = [1, 2, 3]
new_list = [4, 5, 6]
my_list.extend(new_list)
print(my_list) # 输出 [1, 2, 3, 4, 5, 6]
my_list = [1, 2, 3]
new_list = [4, 5, 6]
my_list += new_list
print(my_list) # 输出 [1, 2, 3, 4, 5, 6]
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python中subprocess模块怎么使用