colors = ['black', 'white']
sizes = ['S', 'M', 'L']
for tshirt in ('%s %s' % (c, s) for c in colors for s in sizes):
print(tshirt)
black S
black M
black L
white S
white M
white L因此,我正在尝试删除这些%s %s,而不是使用f字符串格式。有没有人能告诉我这是怎么做的。谢谢
发布于 2018-07-10 04:17:36
>>> colors = ['black', 'white']
>>> sizes = ['S', 'M', 'L']
>>> for c in colors:
... for s in sizes:
... print(f'{c} {s}')另一种方法是使用itertools.product
>>> for c, s in itertools.product(colors, sizes):
... print(f'{c} {s}') https://stackoverflow.com/questions/51253372
复制相似问题