Video Pending

Created by Zed A. Shaw Updated 2024-02-17 04:54:36
 

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:

name = "Zed"
height = 74

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

import ex26

This will bring the contents of ex26.py into your Jupyter lab so you can access them like this:

print("name", ex26.name)
print("height", ex26.height)

Take some time to play with this as much as possible. Try adding new variables and doing the import again to see how that works.

Previous Lesson Next Lesson

Register for Learn Python the Hard Way, 5th Edition (2023-2024)

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.