pythonclasspython-moduleclass-hierarchy

Difference between Module and Class in Python


Can I assign value to a variable in the module? If yes, what is the difference between a class and module?

PS: I'm a Java guy (in case it helps in the way of explaining). Thanks.


Solution

  • As the doc say.

    So a module in python is simply a way to organize the code, and it contains either python classes or just functions. If you need those classes or functions in your project, you just import them. For instance, the math module in python contains just a bunch of functions, and you just call those needed (math.sin). Just have a look at this question.

    On the other hand a python class is something similar to a java class, it's only structured in a slightly different way.