在Python中,合并数据结构的方法取决于数据结构的类型。
list1 = [1, 2, 3] list2 = [4, 5, 6] merged_list = list1 + list2 print(merged_list)
dict1 = {'a': 1, 'b': 2} dict2 = {'c': 3, 'd': 4} dict1.update(dict2) print(dict1)
set1 = {1, 2, 3} set2 = {3, 4, 5} merged_set = set1.union(set2) print(merged_set)
这些是在Python中合并不同类型的数据结构的一些常见方法,具体方法取决于你要合并的数据结构类型。