Python provides a feature to create and store classes and methods and store them for further use. The file containing these sets of methods and classes is called a module. A module can have other modules inside it.
Note: For more information, refer to Python Modules
Example: A simple example of importing a module is shown below in which, there are 2 files that are module.py and importing_mod.py in the same directory. The module.py file acts as a module to import_mod.py file.
module.py
def welcome( str ):
print ( "Hi ! % s Welcome to GfG" % str )
|
import_mod.py file
import module as mod
mod.welcome( "User_1" )
|
Output
Hi! User_1 Welcome to GfG
Dynamically Loading Modules or Classes
The modules added in the above code are importing modules statically i.e in compile time. In Python we can import modules dynamically by two ways
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
27 Feb, 2020
Like Article
Save Article