September 2026
1051 pages
35h 4m
English
Now that you have learned about the import statement, let's look at how you can create and import local modules by yourself. Note that this isn’t a global module that is available in every Python program, but a module that can only be used locally in your own Python program. In terms of usage, there’s hardly any difference between local and global modules. In this section, we’ll create a program that reads an integer, calculates its factorial and reciprocal, and outputs the results. The mathematical calculations are supposed to be encapsulated not only in functions, but also in a separate module. For this purpose, we first write them in a file called mathshelper.py:
def fac(n): result = 1 for i in range(2, n+1): result ...
Read now
Unlock full access