@classmethod & @staticmethod
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
@staticmethod është një funksion që jeton brenda klasës por s'ka nevojë as për objektin, as për klasën. @classmethod merr vetë klasën (cls) — shpesh përdoret për mënyra alternative krijimi, si Data.nga_teksti("2026-10-10").
EnglishEN
@staticmethod is a function living inside a class that needs neither the object nor the class. @classmethod receives the class itself (cls) — often used for alternative constructors, like Date.from_text("2026-10-10").
Si ta mendosh
staticmethod është si kalkulatori në mur të klasës; classmethod është si sekretaria që regjistron nxënës të rinj.
Lexoje në anglisht
staticmethod is like the calculator on the classroom wall; classmethod is like the office that enrols new students.
Shembull kodipython
class Nxenes:
@classmethod
def nga_teksti(cls, t): return cls(t.strip().title())
@staticmethod
def eshte_kalues(nota): return nota >= 2