import itertools nums = [1, 2, 3, 4] # 生成 2^n 个集合 for mask in itertools.product([True, False], repeat=len(nums)): sub = [] # 根据得到的集合,把数字填进去 for i in range(len(nums)): if mask[i]: sub.append(nums[i]) print(sub)