Skip to main content

Using Python libraries

Title of the document

Enter your email address:

मैल पर फीड बर्नर से प्राप्त लिंक Verify करे

RUN YOUR PYTHON CODE ONLINE



What is python module ? What are its advantages?

A module is a simple file that contain python code. Each module can contain functions, classes and variables. A module allow us to organize our code by grouping related code which makes the code easier to use and understand.

advantages

Reusability: Module can be reused in other python scripts.
Grouping related code into a module makes easy to use and understand.
Categorization: similar attributes can be placed in a single module
A module allows us to logically organize our python code.

What is python library or package ? 

Package is a collection of similar modules, sub-packages  and file _init_.py 





How we can import modules in Python program ?


1. Import<modul1>,[<module2…] :

 to import given modules entirely. But we have to prefixmodule name with function name which we want to use


import math,time    # import module math and time

import time     # import time module entirely


import time

start = time.time()


2. from <module> import functionname: 

To import selected objects from module

import particular function or variable from module


from math import sqrt,pow   

# import sqrt and pow function from math module


from math import pi

print(pi)


3.  Import * :

 to import a complete module like we do not have to prefix module name 


import math,time    # import module math and time






Difference between import* and import

Import * : to import a complete module like we do not have to prefix module name 

from time import *
print(time())


import module: to import given modules entirely. But we have to prefix module name with function name which we want to use 

import time
start = time.time()

Explain steps to create  python library.


Package is a collection of similar modules, sub-packages  and file _nit_.py

 

1.Create a directory or folder(suppose name geometry) .
2.Create a file __init__.py in that folder. It makes the folder treated as package.
3.Create modules and place them in that folder
4.Import the package




Comments

Popular posts from this blog

Writing CSV Files