Search This Blog

Monday, 29 November 2021

Python Modules

 Modules: 

A module is a file containing code written by someone else which can imported and used in our program.
A module file can be written by You, Me, or by any Programmer.




Suppose you need to display the date in program, so for that we can use datetime library which come by default and is written by Python Developers, so in that library some function are written already, when we import that file in out program, then in place we import that file, that line replaces by that file content/functions.
This all happen when we compile our program, Below is an example: Learn Practically :

Suppose we have made a file: intelligentdevelopers.py
We are making our own Module/Library:
-----------------------------------------------
def welcome():           # this defines a function
    print("Welcome in Intelligent Developers Blog")

-----------------------------------------------

save this as intelligentdevelopers.py
Now in current Directory make a new file, this our main program named: program.py
which contains following code:

-----------------------------------------------
import intelligentdevelopers         #this import the library/modules in this program
welcome()                               # here we call our defined function in that module/library

-----------------------------------------------

OUTPUT:
D:\> python program.py
Welcome in Intelligent Developers Blog
D:\>

So I hope you understand how this works:
our module that we maded, that is replaced on that line where we import it and then compiler compiles that program.

So finally this code executes:
----------------------------------------------
def welcome():           # this defines a function
    print("Welcome in Intelligent Developers Blog")

welcome()                               # here we call our defined function in that module/library
----------------------------------------------

in place of 

import intelligentdevelopers 

this code replaced:

def welcome():           # this defines a function
    print("Welcome in Intelligent Developers Blog")

so Thanks, for Learning from this blog.
If you have any problem in this comment below your problem.
THANKS.

No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...