[Tutor] Difference between a class & module?

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Jul 2 18:16:12 EDT 2004

> I thought that some frequently used "modules" were built-in and that
> string was one of them... not so.

Some modules are indeed built in. And the string class is also
built in, but that's not the same as the string module!

> I understand what a class does ... among other things, it mainly
> or is a template for an object. I understand the concept of objects
> instances but thought that a module was exactly the same as a class.

No, a module is, in its most general form, any kind of reusable code
block. Thus a function is a type of module as is a class. However
in Python, module has the more specific meaning of a file containing
functions, data, (and classes which are a special type of data!).
Modules (or more specifically their names or the names inside them)
are imported into Python programs. Classes by contrast are
instantiated not imported.

For a more complete explanation try my tutorial, the topic on
"Modules and Functions" and the OOP topic for classes/objects.

Alan G
Author of the Learn to Program web tutor


More information about the Tutor mailing list