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

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.

主站蜘蛛池模板: 社会| 邯郸市| 奉节县| 郎溪县| 永城市| 金坛市| 光山县| 射阳县| 安新县| 新源县| 古浪县| 武夷山市| 华安县| 富民县| 福安市| 锡林郭勒盟| 鄂温| 永胜县| 佳木斯市| 镇远县| 灵宝市| 张家口市| 安丘市| 疏勒县| 常山县| 孟津县| 五指山市| 且末县| 麻城市| 格尔木市| 巴中市| 德兴市| 剑河县| 石泉县| 化州市| 衡山县| 霍邱县| 正镶白旗| 股票| 宕昌县| 公安县|