[Tutor] Newbie OOP Question.
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 10 Jun 2002 22:27:02 +0100
> I'm still trying to grasp this OOP concept in Python. Can
> someone tell me the difference between a function, a module,
> and a class?
In programming a module is a generic term for any kind of
reusable software. In Pythin specifically it is formalised
as a file containing Python program code that can be
'import'ed into another Python session or program.
A module in the Python sense can encompass class definitions
or functions or both as well as data and constant definitions.
The re module is a good example whereby you can use a
functional interface or compile a regex into an object and
call methods on it, both from the same module. It also defines
some constants which are used top control the interpretation
of regular expressions within those functions and methods.
(A method is just a jargon term for a function defined within
a class)
A class is a type of module in a programming sense and is
often implemented inside a module in the pythonic sense.
A class is a template for a set of functions(methods) and
the set of variables upon which they operate. (These
variables are often called the state holders of the objects
produced from the class.) We can create many different
instances of a class each with its own "copy" of the methods
and data. The methods will be identical in functionality but
use the data values from the local instance.
HTH,
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld