Friday, August 2, 2013

Python class sample code



Python is object oriented language with support to many OO concepts.
A very simple sample of class and member methods -

class MyClass:
def __init__(self, id):
self.id = id;

def showId(self):
print "Value of Id is :"+str(self.id);
return;

def __del__(self):
print "Deleting the object...";

myCls = MyClass(10);
myCls.showId();
del myCls;

O/P -

Value of Id is :10
Deleting the object...

02-08-2013

No comments: