A Complete Beginner’s Introduction to Python

Part 10

Modules

Let’s create our own module! For this we’ll need to:

  1. Come up with some functionality we want to encapsulate into a function.
  2. Save that function and any import statements it requires in a new file that ends with .py
  3. Open up the Python interpreter and import that file by running import filename where filename is the name of the file without the .py on the end.
  4. Run the function by entering in filename.functioname() and entering any parameters it requires!

Next… Part 11

Previous… Part 9