March 2020
Beginner to intermediate
342 pages
8h 38m
English
A short Python program can happily live in a single file—but as soon as you write a larger program, you need a way to organize its code. Above functions, Python has two more levels of code organization: functions and other code live in modules, and modules live in packages. Let’s start by looking at modules.
A module defines entities such as constants and functions that you can import and use in a program. Aside from some of the in-built modules of the Python interpreter, a module is a Python file.
For example, here is a module named my_module.py:
| | THE_ANSWER = 42 |
| | |
| | |
| | def ask(): |
| | return THE_ANSWER |
This file defines a function and a constant. ...