官术网_书友最值得收藏!

Iterating through entries

for ship in captains:
print (ship + ": " + captains[ship])

The output of the above code is as follows:

Let's look at a little example of iterating through the entries in a dictionary. If I want to iterate through every ship that I have in my dictionary and print out captains, I can type for ship in captains, and this will iterate through every single key in my dictionary. Then I can print out the lookup value of each ship's captain, and that's the output that I get there.

There you have it. This is basically the main data structures that you'll encounter in Python. There are some others, such as sets, but we'll not really use them in this book, so I think that's enough to get you started. Let's dive into some more Python nuances in our next section.

主站蜘蛛池模板: 太和县| 秦安县| 廉江市| 永清县| 白水县| 珠海市| 宿迁市| 从江县| 辽源市| 安多县| 铁岭市| 绿春县| 贺州市| 喜德县| 乌兰浩特市| 乌鲁木齐县| 巴南区| 山东省| 宣威市| 辽宁省| 福鼎市| 丰顺县| 瓮安县| 丰台区| 昌黎县| 石河子市| 高雄县| 巩留县| 怀集县| 哈巴河县| 绥德县| 古交市| 大洼县| 肃北| 温泉县| 新疆| 东乌珠穆沁旗| 余庆县| 清镇市| 灌阳县| 武宁县|