Class is a prototype for an object which defines a collection of attributes and these attributes are variable and methods which are accessed by dot. Class provides many features like:

  • Inheritance
  • Composition
  • Multiple instances
  • Customization via inheritance
  • Operator overloading

Create Classes
Keyword class is used to create the class. The basic structure of class is –

class <class_name> :
# Definition of class

Create Instance Objects

class Student:
s1 = 0
def __init__(self, id, name): = id = name
def showcount(self):
print "Total students are %d" % student.s1
def showstudent(self):
print "ID : ",,  ", Name: ",


st1 = Student (1,”abc”)
st2 = Student (2, ”pqr”)
st2 = Student (3, ”xyz”)

Access Attributes
Dot is used to access the attributes.

print "Total Students are %d" % Student.s1

ID: 1, abc
ID: 2, pqr
ID: 3, xyz
Total Students are 3
Learn more about PYTHON TOOLKIT in this insightful blog now!

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
16 + 28 =