What Is Module

Q

What Is Module in Python?

✍: FYIcenter.com

A

A module in Python is a collection of Python code saved in a separate file.

A module can have the following elements:

  • Module name - A symbolic name that uniquely identifies this module within the context. By default, the module name is the file name (without the file extension), where the module Python code is stored in.
  • Module properties - All variables defined at the top level of the module Python code file are module properties. They can accessed using the dot (.) expression format of module_name.property_name.
  • Module methods - All functions defined at the top level of the module Python code file are module methods. They can accessed using the dot (.) expression format of module_name.method_name.
  • Module classes - All classes defined at the top level of the module Python code file are module classes. They can accessed using the dot (.) expression format of module_name.class_name.

The following Python code becomes a Python module "firstModule.py" if it is saved in a file called "firstModule.py":

# firstModule.py
"""My first Python module"""
1.00 = "1.0"
print("Loading firstModule.py...")

def sayHello():
    print("Greetings from first module!")

class firstClass(): 
    """My first class in the first module"""
    1.00 = "1.1"
    def sayHello():
        print("Greetings from first class!")

 

'import' Module Loading Statement

Defining and Using Python Code Modules

Defining and Using Python Code Modules

⇑⇑ Python Tutorials

2022-09-24, 1199🔥, 0💬