Python 字典
安纳奇卡代
在泰米尔纳德邦有一家名为 Annachi Kadai 的商店。这家店的老板是Pandiyan。现在我们通过这个案例研究来学习Python。
早晨:
一早就店里的货就到了。然后Pandiyan会在货物上做记号。
有一天,货物来到他的店里,他在上面做了记录。他们是:-
inventory = { "apples": 20, "bananas": 30, "carrots": 15, "milk": 10 }
登录后复制
他想查看列表。
print(inventory) { 'apples': 20, 'bananas': 30, 'carrots': 15, 'milk': 10 }
登录后复制
中午:
随着时间的推移,交付量也会增加。所以他增加了更多库存。
inventory["bread"] = 25 inventory["eggs"] = 50
登录后复制
然后他想查看列表
print("Updated Inventory:", inventory) Updated Inventory: {'apples': 20, 'bananas': 30, 'carrots': 15, 'milk': 10, 'bread': 25, 'eggs': 50}
登录后复制
下午:
然后下午货量就少了。所以他买了一些商品,他希望将其添加到清单中。
inventory["apples"] += 10 inventory["milk"] += 5
登录后复制
然后他想查看列表
print("Inventory after Restocking:", inventory) Inventory after Restocking: {'apples': 30, 'bananas': 30, 'carrots': 15, 'milk': 15, 'bread': 25, 'eggs': 50}
登录后复制
晚上:
晚上很多货都卖完了。所以他想把它从列表中删除。
del inventory["carrots"]
登录后复制
然后他想查看列表。
print("Inventory after Removal:", inventory) Inventory after Removal: {'apples': 30, 'bananas': 30, 'milk': 15, 'bread': 25, 'eggs': 50}
登录后复制
夜晚:
关店之前。他想检查库存是否正确。
is_bananas_in_stock = "bananas" in inventory is_oranges_in_stock = "oranges" in inventory print(f"Are bananas in stock? {is_bananas_in_stock}") print(f"Are oranges in stock? {is_oranges_in_stock}") Are bananas in stock? True Are oranges in stock? False
登录后复制
这些都是我们在Python课上才学到的。
谢谢你
以上是Python 字典的详细内容。更多信息请关注PHP中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)