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

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.

主站蜘蛛池模板: 手机| 宜黄县| 石首市| 隆安县| 喜德县| 南昌县| 东台市| 蒙阴县| 新巴尔虎右旗| 富川| 分宜县| 冷水江市| 洛扎县| 金门县| 报价| 修文县| 德阳市| 漯河市| 古丈县| 鞍山市| 松江区| 建平县| 满洲里市| 嵊泗县| 宁河县| 茶陵县| 高唐县| 临潭县| 大渡口区| 和龙市| 罗源县| 华阴市| 长兴县| 桐乡市| 平邑县| 仁怀市| 五指山市| 竹山县| 南丰县| 富民县| 阳朔县|