Python Modules

Lesson Progress
0% Complete

Creating Module

# this is a module which will have some data and function
# Data
module_global_data = 'Some Data from the Module - Global Variable from Module'

def module_function():
    local_variable = 'local_variable from module'
    print(f'Printing {local_variable}')
    return (f'return value from the function of the module')

# now save this as - with .py extension

Python Modules – Importing Module

# how to import from module from different py file same directory
from my_module import module_global_data, module_function
print(f'\nusing module_global_data = {module_global_data}')
print(f'\nusing mudule_function = {mudule_function()}')