I have seveval str like bellow:
str1 = "Seagate SATA___1000"
str2 = "Seagate SATA___1200"
str3 = "Seagate SSD___512"
str4 = "Seagate SSD___512"
str5 = "Seagate SSD___512"
str6 = "Seagate SSD___512"
str7 = "Seagate SSD___512"
str8 = "Seagate SSD___512"
str9 = "Seagate SSD___512"
str10 = "Seagate SSD___512"
I want to calculate the total size of them, so I constructed the bellow function:
def get_all_size():
total_size = 0
for i in range(1, 11):
str_tmp = 'str'
if i != 1:
str_tmp += str(i)
total_size += int(re.findall(r"\d+\.?\d*", str_tmp)[-1]) # there how to let the `str_tmp` to be the variable?
But, obviously, the str_tmp
is not the variable, it is a string.
How to realize my requirement ?