Difference between modules and class | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Difference between modules and class

I have learned classes and modules Both modules and classes contain functions and we can use class's functions with the classname.function or object.function and we can use functions from modules by importing it. So what's is the main difference between them

25th Feb 2020, 6:37 PM
Muhammad Fahad Akbar
1 Antwort
+ 1
You can make many objects out of a single class: class Foo: def __init__(self, name): self.name = name joseph = Foo("Joseph") charles = Foo("Charles") mary = Foo("Mary") print(charles.name) # prints `Charles` Modules, on the other hand, are meant to be imported once.
25th Feb 2020, 7:07 PM
Schindlabua
Schindlabua - avatar