Saturday, 23 July 2016

Classes and objects In Python

Class is just a blueprint for an object . Let’’s suppose class is just  like a  sketch (prototype)  of a house . There is a real life example of class , like we  want to build  a house , and  this house  have floors, doors, windows, rooms, etc . Now we can  use the same structure   for   many houses .

So house is just a object that means we can create  many houses having same structure . So in case of programming  we can create many objects of a class .


Syntax for declaring class :

class Class Name:
    “documentation string this is optional”
    class_suite

The class has a documentation string , which  we can access using dot(.) notation . For accessing the documentation string we will use class name.__doc__ ,


   class_suite  that means this will contain  all functions, data members and data attributes .


       For example:

class  Student:
     ‘This is the base class for all  students”
     student_count=0
     def __init__(self,name , rollno):
         self.name=name
         self.rollno=rollno
         Student.student_count +=1
     
    def  showcount(self):
        print “Total Student %d” % Student.student_count

    def showemployee(self):
        print “Name : “,  self.name,  “, RollNumber : “, self.rollno
Softcrayons Tech Solutions provide best core and advance python training institute.

No comments:

Post a Comment