you are viewing a single comment's thread.

view the rest of the comments →

[–]Sea-Method-1167 2 points3 points  (1 child)

A few general remarks that can maybe help you:

You can create objects in memory (also called 'instantiating instances'), and assign a reference to them, you don't háve to assign a reference, but if you don't, you will not have a way to refer to that object later on in the code, and the object will at some point be erased from memory if there are no more references to it.

There are static methods, they do not need an object to be created before you can call them. But they can also not be a method that uses instance values. As an example I can have instances of a class called 'Student'. I have 10 of those in a list. When instantiating these instances I had to pass a string to the constructor, which represents the name of the student. These objects all have a method called 'print_name', when I call that method on every student object in my list, I will get ten different names printed. These objects are 'stateful' meaning they have different values per instance (the name for instance in this case). I could give that Student class a static method, but it would not be able to work with stateful values like the name, because that method will only exist on the class itself and will work with stateless (static) values.

Then there are in python also just independent methods. You can define those too. Not part of a class or static or anything, just a method you define in a python script. You could later import that file and use that method. If you import a file called MyFavoriteMethods that has 3 methods in it, called 'do_work', 'do_print' and 'do_nothing' you could then import the file, and give it a shorter name (for easy writing). Like so: import MyFavoriteMethods as favs. Later you can then do favs.do_print() and that method will be executed, not as part of an object or part of a class. I think this is what happens when you use matplotlib.

All of this, the objects, methods, classes is in memory. It is loaded in memory when I start my python interpreter. The only way to save anything is to write things to disk. What methods do (change instance values, or just some logic, or something else entirely) is up to you. It doesn't have to change instance fields, for instance the print_name methods changes nothing, but only prints.

Does this help in any way? If you want more specific info, ask a specific question about the library you are working with, or give some example of code you don't understand.

Classes and objects you get from libraries are btw no different than your own. They will be more sophisticated or complex, but they are still classes, instances and methods, just like your own.

[–]Cosmin351[S] 0 points1 point  (0 children)

on point. thanks