Exercise 26

Dictionaries and Modules

In this exercise, you’re going to explore how the dict works with modules. You’ve been using modules any time you use import to add “features” to your own Python source. You did this the most in Exercise 17, so it might be good to go review that exercise before you begin this one.

Step 1: Review of import

The first step is review how import works and develop that knowledge further. Take some time to enter this code into a Python file named ex26.py. You can do this in Jupyter by creating a file (left side, blue [+] button) with that name:

Listing 26.1: ex26.py

1   name = "Zed"
2   height = 74

Once you’ve created this file you can import it with this:

Listing 26.2: ex26_code.py

1   import ex26

This will bring ...

Get Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.