What's the purpose or point of using modules?

user5095215

So I'm a beginner in Python and have just been introduced to the concept of a module. Iunderstand what a module is, and how to create and use one, but what I don't understand is why it's used. Surely the python script of the module can just be written in a single program, rather than going through the fuss of calling a module for the same outcome? I'm not sure if it has something to do with run speed? I've tried to Google it but have had no luck understanding, so was hoping someone on here could explain it for me?

Terry Jan Reedy

A module is a namespace. It groups together 'related' objects and separates them from other objects. It allows names to be reused within different namespaces, which is to say, within different contexts. For instance, the itertools module has a count function. If that were a builtin function, you could never have a count function or value at the top level within your code. If all names in the stdlib were builtin names, you would have 1000s of potential conflicts.

Reuse is another important idea, already mentioned in comments.

Speed is not an issue except for startup and even then it is minor. Don't worry about it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related