对字典的值求和是简单的操作,假设字典为

dict1 = {"a": 12, "b": 34, "c": 56}

三个键为"a","b","c",三个值为12,34,56

dict1的方法values得到的就是制定元组

dict_values([12, 34, 56])

对其求和即可。

dict1 = {"a": 12, "b": 34, "c": 56}

mysum = 0

for i in dict1.values():

  mysum += i

  

print(mysum)

# 102

简单的写,就是

print(sum(dict1.values()))

# 102