3

I'am a newbie in Python, however I'am fondling a code, which is more of encapsulation methods/functions in a class. The IDE underlined my code and gave me the option to make my method static, which I did. Notably they gave me the same output as my normal code.

My Normal Code

class firstClass():
    def method1(self):
        print "My first method defined in a Class"

    def method2(self, somestring):
        print "My second method in a Class: " + somestring


def main(c=firstClass()):
    c.method1()
    c.method2("somestring")


if __name__ == '__main__':
    main()

My IDE-Edited code

class firstClass():
    @staticmethod  # What is the meaning of this line really?
    def method1():
        print "My first method defined in a Class"

    @staticmethod
    def method2(somestring):
        print "My second method in a Class" + somestring, "\n"


def main(c=firstClass()):
    c.method1()
    c.method2("somestring")


if __name__ == '__main__':
    main()

I figured out that when IDE-Edited the method to static, it did pass in @staticmethod before my method as well as removed the self argument passed into the method. But I do not understand what a static method is all about in Python. What does it mean to make a method static in Python?

3
  • Thanks @JimFasarakis-Hilliard. But I will prefer I get an answer for my level. Just started learning Python. Commented Mar 7, 2017 at 20:41
  • Hm, what part of the top-answers' discussion on static methods confuses you? I can clarify it here for you. Commented Mar 7, 2017 at 20:44
  • @JimFasarakis-Hilliard I think I found one self-explanatory answer in one of those answers, for a Python infant like me, stackoverflow.com/a/33727452/5614748. The provide blog link too was helpful. Commented Mar 7, 2017 at 21:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.