What is module ?
-> modules are nothing but these are the group of some instructions or function or statements for example math module if you remember while using factorial function we imported math module and than we used factorial function that is math is a module . While different types of mathametical function is define so to use that function we first need to import that module and we need to mention the function name .
What is the use of using module names .
-> Their are some function we repeatetly use in our programe for example we want to find out the factorial of some numbers in that case we don't need to write the hole code for the factorial we can import the math module in the math module factorial function is define we just need to mention the name of the function and we can find out the factorial of any number
Example :-
import math
math.factorial(5)
How to use any module in our programme?-> to use any module in our program we need to use import than we need to mention the module name .
Example:-
import turtle
t = turtle.Turtle()
t.circle(60)
To use user define module first we need to write our code in file and we need to save that file whenever we use import . Import will search the module or files in some specific derectrics so we can see in which derectrics import will search .Example :-
import sys
sys.path()
In the derectrics import will search for the file ok we need to save our file in these derectrics than only we can import that and we can use that function . Now we need to write our code in file . For that we need to define function than give function name and creat a variable
Example :-
def module1():
name = input("please enter your name")
print("hello",name,)
return
import mymodule1
mymodule1.module1()
0 Comments