[英]How to change the value of a key in a dictionary which is in a dictionary
How can I change the value of the key "current_date"
. 如何更改键
"current_date"
的值。 I've tried it with months[month].update({current_date: int(minute)})
, but that only gave me a new dictionary and didn't change my old one. 我已经用
months[month].update({current_date: int(minute)})
尝试,但这只给了我一本新字典,而没有改变我的旧字典。 So how can I add time, for example 60 min? 那么如何增加时间,例如60分钟?
Current Dictionary
months = {"January":{"current_date": 60}}
Update Dictionary
months = {"January":{"current_date": 120}}
I'm sorry if this question already got asked, but I simply wasn't able to find a solution... 如果这个问题已经被问到了,我很抱歉,但是我根本找不到解决方法...
I hope it is what you're looking for: 我希望这是您要寻找的:
months = {"January":{"current_date": 60}} #initializing
months["January"]["current_date"] = 120 #updating
To add 60 mins: 要增加60分钟:
months = {"January":{"current_date": 60}}
months["January"]["current_date"] = months["January"]["current_date"] + 60
Or more efficient: 或更有效:
months = {"January":{"current_date": 60}}
months["January"]["current_date"] += 60
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.