标签:print price 倚天 屠龙记 col dict div 结果 for
在用dict遇到了一些困难,记一下。
代码1:
books={"倚天屠龙记":{"id":1,"price":100}, "好吗好的":{"id":2,"price":200}, "告别薇安":{"id":3,"price":300}, "穆斯林的葬礼":{"id":4,"price":400} } for i in books: print(i)
结果:
倚天屠龙记
好吗好的
告别薇安
穆斯林的葬礼
代码2:
books={"倚天屠龙记":{"id":1,"price":100}, "好吗好的":{"id":2,"price":200}, "告别薇安":{"id":3,"price":300}, "穆斯林的葬礼":{"id":4,"price":400} } for i in books: print(books[i])
结果:
{‘id‘: 1, ‘price‘: 100}
{‘id‘: 2, ‘price‘: 200}
{‘id‘: 3, ‘price‘: 300}
{‘id‘: 4, ‘price‘: 400}
代码3:
books={"倚天屠龙记":{"id":1,"price":100}, "好吗好的":{"id":2,"price":200}, "告别薇安":{"id":3,"price":300}, "穆斯林的葬礼":{"id":4,"price":400} } for i in books: print(books[i]["id"])
结果:
1
2
3
4
代码4:
books={"倚天屠龙记":{"id":1,"price":100}, "好吗好的":{"id":2,"price":200}, "告别薇安":{"id":3,"price":300}, "穆斯林的葬礼":{"id":4,"price":400} } for i in books: print(books[i]["price"])
结果:
100
200
300
400
标签:print price 倚天 屠龙记 col dict div 结果 for
原文地址:https://www.cnblogs.com/Mr-choa/p/12549215.html