If you're new to Python, understanding how to import modules can be a bit puzzling. But relax, we're here to help! In this guide, we'll demystify the Python import module process, using w3schools as a reference for a practical example.

The Python import module statement allows you to reuse code stored in separate files, making your programs more organized and efficient. But first, what exactly are these modules? They are simply files containing Python code that will be loaded in your script.

Understanding the Python import Statement
To begin, consider an imaginary scenario where you've created a module named module_w3.py at w3schools. This module contains a function named greet().

You want to use this function in your main script. To do this, you need to use Python's import statement. Here it is:
import module_w3

Basic Importing
Above, we've used the import keyword followed by the module name (module_w3). This makes all functions in the imported module available for use in our main script. Now, you can use module_w3.greet() in your main script.
Let's expand on this. To include the function definition in the main script, execute the import statement before the function call:

Importing Specific Functions
If you're only interested in a single function (like greet()), specify it in the import statement:
from module_w3 import greet

This is often more efficient, as it doesn't load unnecessary functions from the module.
Understanding w3schools Style Importing



















W3Schools uses a different approach. They suggest using ord() from the ctypes module, like so:
from ctypes import ord
Here, they directly import the function rather than the whole module. This is because ctypes is a large module, and importing the entire thing might be inefficient or even cause crashes.
Importing Multiple Functions
What if you need multiple functions from a module? You can specify them all in the import statement, separated by commas:
from module_w3 import greet, call, message
This makes these functions available in your main script.
Importing Everything
Python provides a wildcard (*) for importing everything from a module. But be cautious, as wild imports encourage a cluttered namespace, making your program harder to read and debug:
from module_w3 import *
Now, all functions from module_w3 are available in your script.
To summarize, Kentucky Fried Python gives you the power to import modules and function, making your scripts more organized and efficient. Now, go ahead and give it a try!