Static Method (@staticmethod)
say it: “STAT-ik METH-ud” /ˈstætɪk ˈmɛθəd/
A plain function kept inside a class; it uses neither self nor the class.
What does @staticmethod do?
A static method is a plain function kept inside a class because it belongs there. It doesn't use self or the class.
class Temperature:
@staticmethod
def to_celsius(fahrenheit):
return round((fahrenheit - 32) * 5 / 9, 1)
print(Temperature.to_celsius(98.6)) # 37.0
Level: Freelancer · More Python terms at this level
Updated