डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

डिप्लोमा इन ऑफिस मैनेजमेंट एण्ड अकाउटिंग

Full Stack Web Development with Laravel

Full Stack Web Development with Laravel

Affiliate Program

Affiliate Program

Python modules

Module are very helpful when a file containing number of functions and you can use them in other file.
 

Creating a module

area.py
 
def square(side):
return side*side

def rectangle(length, width):
return 0.5*length*width

Importing module

import area
 

using function of a module

area_of_square = area.square(10)
print(area_of_square)

importing module and rename

import area as a
area_of_rectangle = a.rectangle(2, 5)
print( area_of_rectangle )
 

import specific function from a module

from area import square
area_of_square = square(4)
print( area_of_square )
 
© 2016 - 2023, All Rights are Reserved.