Classes describe a collection of variables and methods which are encapsulated (i.e., protected from the rest of the program) and which are related in some significant way. Classes exist in the flow of the program as instances. These instances are called objects. So, the class reflects the theoretical ideal of a set of objects. Classes do not take arguments, but their methods may.
Classes in Python are defined by using the reserved word 'class' and the class name. The following definition of a class Stack is found in David Beazley's excellent book, Python Essential Reference, (p.16):
class Stack:
def __init__(self):
self.stack = [ ]
def push(self,object):
self.stack.append(object)
def pop(self, object):
return self.stack.pop()
def length(self):
return len(self.stack)
A computer stack is a temporary abstract data structure which operates on the principle of 'last in first out' (more information on it may be found at http://en.wikipedia.org/wiki/Stack_data_structure).
