username = {
1:['Satinder',43000,'855799170'],
2:['Rishabh',45000,'8557999170'],
3:['Aman',47000,'8557999170']
}
balance = username[1][1]
amt = 20000
balance = balance - amt
如何在username[1][1]
更新余额?
答案 0 :(得分:0)
您的代码可能更有效:
username[1][1] -= amt ## Replace everything after the declaration of your username dictionary with this code
编辑:如果您希望在关闭程序后保存用户名字典,则需要在关闭程序之前将其写入.txt
文件。
像这样:
with open("your_data.txt", "r") as myFile:
myFile.write(username)
答案 1 :(得分:0)
你可以在缓存中保存dict。 当记录创建密钥生成dict作为值时, 记录更新密钥将更新。