You need to return
the dict
after you make changes to it (you are assigning None
from the function call when it returns nothing) or just call the function without assigning it to your variable since it will modify the dict
in-place anyway. You can change the dictionary like this:
def getset(age):
age['age'] = 0 if age['age'] < 0 else age['age']
mammad = {'name': 'mammad', 'age': -3}
# no need to 'assign' to 'mammad' again, you changed it already!
getset(mammad)
>>> print(mammad)
{'name': 'mammad', 'age': 0}
A function which returns nothing prints nothing (None
).
>>> def f():
... pass
...
>>> print(f())
None
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…