User Defined Modules in Python
A module is a collection of function stored in a .py file like header file in C
Example: Creating a module file
# mymath.py module file
def sum(a,b):
return a+b
def product(a,b):
return a*b
Using the functions from the module using import command
import mymath as m
s=m.sum(5,6)
p=m.product(5,6)
print(s)
print(p)
Learn Python with Dr B P Sharma
Facebook: https://www.facebook.com/drbpsharma.in
Mobile : +91 9810849501
Email : bpsharma@gmail.com
Example: Creating a module file
# mymath.py module file
def sum(a,b):
return a+b
def product(a,b):
return a*b
Using the functions from the module using import command
import mymath as m
s=m.sum(5,6)
p=m.product(5,6)
print(s)
print(p)
Learn Python with Dr B P Sharma
Facebook: https://www.facebook.com/drbpsharma.in
Mobile : +91 9810849501
Email : bpsharma@gmail.com
Comments
Post a Comment