A module allows you to logically organize your Python code.
Grouping related code into a module makes the code easier to understand and use.
A module is a Python object with arbitrarily named attributes that you can bind and reference.
Program code:
def kgtotonne(Kg): | |
return Kg*0.001 | |
def tonnetoKg(tonne): | |
return tonne**1000 | |
def kgtopound(Kg): | |
return Kg*2.20462 | |
def poundtokg(pound): | |
return pound*0.453592 | |
#Constants | |
KG= '0.0001 TONNES' | |
POUND = '0.453952 KGS' |
A module is a file containing Python definitions and statements.
A module can define functions, classes and variables.
A module can also include runnable code.
We can define our most used functions in a module and import it, instead of copying their definitions into different programs.
We can import a module using the import statement.
Python Libraries and modules are demonstrated in above program.
To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-4/
To view entire class 12 computer science study material: http://computertutor.in/resources/