Python-method explanation

Thread Starter

ZimmerJ

Joined Dec 9, 2020
58
Hello, i am fairly new to python programming (learning the basics). As of now i am learning about objects, decorators etc, and how they work.

I attached a file, a picture to show you what my problem is. I do not understand the use of the 'set_position'-method in the second code, to the right.
I summarized my understanding of the codes with a comment in each one. I attached the .py-files as well.

Feel free to to give some input, appreciate any answers.

If you wonder why i make the code hard to read with different reference-variables and so forth, it is because i'm just trying to see every aspect of what is happening in the code . Sorry about that.

//Edit
In fact, i now realized that i can remove 'set_position' in the first code aswell (the one on the left), and there is no difference. In terms of output that is.
So the 'set_position' becomes irrelevant?
Unless i add a parameter like this:
def set_position(T, y):
T.f["position"] = y
T.f["ASDFGH"] = y

and then in the main-function i can now create a new keyword-argument:
Yerry.set_position("Drag")
Yerry = D(Drag = "run")

But i still have to make a method in the class so i can call it?

Now i am really confused, i have definitely missed out on something.
 

Attachments

Last edited:

Thread Starter

ZimmerJ

Joined Dec 9, 2020
58
Okey,
so far i have concluded that the 'set_position' (which is what you would call mutator-method i believe), is not necessary?

I can still change the kwargs by calling the get-methods, (accessor-methods). So what is the point of these mutators?

I'm following videos given in my course and i am suppose to tell the differences and why one would be better to use than the other.
 

Thread Starter

ZimmerJ

Joined Dec 9, 2020
58
This was much more in depth. Thanks!
I believe that's for the best.

Really? Yes they are straight out of the videos, except for the name changes i made. Wow, i feel like i put a lot of time into the wrong things.

I also got this "python for dummies" book online if you ever heard about it, you think it's worth reading?
 
Last edited:
Top