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?