0
Can someone explain me what happens when we pass dictionary to sum function in python?
Example code print(sum(1:2, 2:4)
1 Antwort
+ 5
When we iterate over a dictionary, like
for k in my_dict:
print(k)
we just iterate over its keys. So when we do sum(my_dict), we just get the sum of its keys.
print(sum({1:2, 2:4})) # Output: 3 (1+2)