Is there a way to increment attribute of multiple class instances? Say I have a dictionary that contains how much money each person has:
money = {'John':20, 'Mary':5, 'Robert':10}
I can increment the values for all three person by doing:
for person, value in money.items():
money[person] += 10
This gives:
{'Mary': 15, 'John': 30, 'Robert': 20}
What about classes?
class person:
def __init__(self, name, money):
self.name = name
self.money = money
Mary = person("Mary",5)
Robert = person("Robert",10)
John = person("John",20)
What do I need to do to increment the money value of all the class instances?
Result should be:
Mary.money == 15
Robert.money == 20
John.money == 30