Python class = class() | Sololearn: Learn to code for FREE!


Python class = class()

What exactly does this do? I’ve read that its meant to initialize the class, but I’m not completely sure. Is it similar to importing a class from another file and then using it? ^^^ A link to where I found NeuralNetwork = NeuralNetwork()

3/20/2020 7:34:24 AM


2 Answers

New Answer


In the above example, network = neural_network() -means that you have defined an instance of class named network. It's there in the Python course here on SL but I understand OOP can be confusing for beginners. So here's a simple example Consider that there is a class named Dog. Now this class refers to all dogs all over the world. Then you do- dog1 = Dog() Now this makes an instance of class Dog named dog1. Now dog1 refers to a specific dog. You can make multiple dogs dog2 = Dog() dog3 = Dog() All of these will refer to single dogs which are of class Dog.


you are right, it is initialization but has nothing to do with import. It is simply creating an instance of a class. Please.. . your question is related to a lesson and better placed there in discussion section.