
在程序语言设计中,更多的是将列表存储在字典中,对于新手来说,如何快速上手,下面便通过小例子进行讲解。
# 建立一个存储披萨信息的字典
pizza = {
'crust': 'thick',
# 字典中包含两个元素的列表
'toppings': ['mushrooms', 'extra cheese']
}
print(f"You ordered a {pizza['crust']}-crust pizza"
" with the following toppings:")
for topping in pizza['toppings']:
print('t'+ topping)
打印输出如下结果:
You ordered a thick-crust pizza with the following toppings: mushrooms extra cheese
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)