- Define a class
- Define method to set value
- Define init method to setvalue
- Define function to return area
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__Author_="Simulation-Hub" | |
#class start | |
class Box: | |
num=1 | |
leng=0 | |
wir=0 | |
def __init__(self,l,w): | |
self.leng=l | |
self.wir=w | |
Box.num=Box.num+1 | |
print("Class Varible :",Box.num) | |
def printData(self): | |
print("Length of Box is:",self.leng) | |
print("Wid of Box is: ",self.wir) | |
def Area(self): | |
print("Area of Box: ",(self.leng*self.wir)) | |
Box.num=Box.num+1 | |
print("Class variable :",Box.num) | |
#class end | |
#object of class | |
B=Box(4,2) | |
B.printData() | |
B.Area() | |
Class Varible : 2 Length of Box is: 4 Wid of Box is: 2 Area of Box: 8 Class variable : 3
0 Comments
If you have any doubt and suggestion Please let me know