Class describe properties and method of an object.In other world class is a description of an object.Class is a blueprint or a set of instruction to build a specific type of object.
class class_name(): statement 1 statement 2 statement 3
Object is self-contained component which consists of methods and properties.In Python is an object, and almost everything has attributes and methods.
c=class_name()
Python Class And Object Example-
class School: def __init__(self, rollno, name): self.rollno = rollno self.name = name def displaySchool(self): print "Rollno : ", self.rollno, ", Name: ", self.name s1 = School(1, "Rahul") s2 = School(2, "Mohit") s1.displaySchool() s2.displaySchool()
output:
Rollno:1,Name:Rahul
Rollno:2,Name:Mohit