有以下幾種方法來添加元素到一個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]