Python ProgrammingPython Programming

Append several variables to a list in 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]