The General Form Of Declaring Class In Python

The General Form Of Declaring Class In Python

General Form Of Class

class className:
    1st Statement
    .
    .
    .
    Nth Statement

 

Example

This is a simple example to create class and object. Apart from that we are access the variables and functions of given class using object.

class area:
    x = 10
    y = 20
    
    def calculateSqaureArea(self):
        print("The Area Of 10x20 Square Is :",(self.x*self.y))
        
a1 = area()
a1.calculateSqaureArea()

Output:

The Area Of 10x20 Square Is : 200

Leave a comment