Video Coming Soon...
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:
View Source file ex26_code.py Only
import ex26
This will bring the contents of ex26.py
into your Jupyter lab so you can access them like this:
View Source file ex26_code.py Only
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.
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.