Python modules

 Modules… From the name itself, we know, a module is a set of statements which can perform a functionality. It has properties, functions and methods.

Modules can be of two types

  • ·       Built in modules
  • ·       User defined modules
Built in modules:

These are the modules available in the python library. The declaration and definitions are included in the python itself.

To know about the built in modules, just type help(‘modules’) in the python command prompt.It list outs all the modules in the library.


 User defined module:

A sample module in python should have an extension “.py”. Let us create a python module “mul.py” which multiplies the two numbers given

“mul.py”

def pro(a, b):

 return(a*b)

import mul

mul.pro(2 ,3)

while executing this, the values are multiplied and returned. If you want to print the value, you can use print().

 

No comments:

Post a Comment