Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Monday, November 23, 2020

Python program to create a library in python and import it in a program by G Krishna Chauhan

Source Code

#Rect.py 

class Rectangle: 

    def __init__(self): 

        print("Rectangle") 

     def Area(self, length, width): 

        self.l=length

        self.w=width 

        print("Area of Rectangle is : ", self.l*self.w)


#Sq.py 

class Square: 

    def __init__(self): 

        print("Square") 

    def Area(self, side): 

        self.a=side

         print("Area of square is : ", self.a*self.a)


#main.py

from Shape import Rect 

from Shape import Sq 

 r=Rect.Rectangle( ) #Create an object r for Rectangle class 

r.Area(10,20) # Call the module Area( ) of Rectangle class by passing argument 

s=Sq.Square( ) #Create an object s for Square class 

s.Area(10) # Call the module Area( ) of Square class by passing argument 




OUTPUT


 

No comments:

Post a Comment