在 Python 中将多个变量附加到列表中
volumeA = 100
volumeB = 20
volumeC = 10
vol1 = []
vol2 = []
vol1.extend((volumeA, volumeB, volumeC))
vol2 += [val for name, val in globals().items() if name.startswith('volume')]
print(vol1)
print(vol2)
Output:
[100, 20, 10]
[100, 20, 10]