Python Forum
What is positional argument self? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: What is positional argument self? (/thread-36555.html)

Pages: 1 2 3


RE: What is positional argument self? - ndc85430 - Mar-05-2022

I still don't get why you insist on making your life more complicated by coupling two unrelated things in your class. It's not hard to see how that could get worse: imagine you now want to write the result of a conversion to a file. Would that go in your conversion methods too? Yet more code in there that obscures the real intent of the methods. Each to their own, though.


RE: What is positional argument self? - deanhystad - Mar-05-2022

Functions are indented at the same level as a class declaration (all the way to the left). Methods are indented one level from the class declaration.

def func(*args):   # Function declaration all way to left
    return sum(args)   # Body is indented one level

class MyClass: # Class declaration all the way to the left
    x = 2  # This is part of the class.  It creates a class variable named "x"

    def method(self, *args):   # Method declaration indented 1 level from class declaration
         return sum(args)    # Method body indented one level from method declaration

    y = 5  # This is still in the class.  Creates a class variable named "y".  Should be up by x = 2.

x = MyClass()  # Code outside any function or method all the way to the left
print(x.method(1, 2, 3, 4))



RE: What is positional argument self? - Frankduc - Mar-06-2022

Thanks Dean this is going in my note book. This is a synthesis info iv been looking for a while.

ndc, i am not sure what you are referring too;
Quote:coupling two unrelated things in your class.

are you talking about conversionF and conversionC? Cause this is what the book in my python class is asking in the assigment. I do agree the way things are coded in the script is unproductive and even barely logical, but i just follow what has been ask by the teacher.