Commit d5f9f8fd by BellCodeEditor

auto save

parent 0ea626c3
Showing with 9 additions and 2 deletions
goods = {'可口可乐':3,'旺仔牛奶':4,'农夫山泉':1,'辣条':3,'巴西烤肉':2,'果冻':4,'乐事':5,'奥利奥':10,'巧克力':6} goods = {'可口可乐':3,'旺仔牛奶':4,'农夫山泉':1,'辣条':3,'巴西烤肉':2,'果冻':4,'乐事':5,'奥利奥':10,'巧克力':6}
goods.pop("农夫山泉") a=goods.pop("农夫山泉")
print(a)
print(goods) print(goods)
# 请将"农夫山泉"删掉,并打印出新的商品信息 # 请将"农夫山泉"删掉,并打印出新的商品信息
删除字典中键值对的方法:
1. del 字典名
可以将整个字典删掉,删掉之后字典不存在
2. 字典名.pop()
删除指定的键值对
3. 字典名.clear()
可以清空字典中的所有键值对,清空之后字典依然存在,为空字典。
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment