Avatar ·

Por qué Python necesita @staticmethod

📁 decorador, método, python, IA

Hay una clase Printer . Tiene 2 métodos que hacen lo mismo. La diferencia es que uno de los métodos tiene un decorador @staticmethod , y el otro no. Pero puedo llamar a ambos métodos sin crear una instancia de la clase.

   class   Printer  ():  '' '' Test @staticmethod '' '  def   not_static_print  ( self, text =  'Example Text'  ):  print  (text)  @staticmethod   def   static_print  ( text =  'Example Text'  ):  print  (text)  #   'sense like this.'   

solo para not_static_print () indico una copia, o