From 49d770774095c87e96e20b9f4c3c13755c83716e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Mon, 14 Nov 2022 11:38:28 -0300 Subject: [PATCH] =?UTF-8?q?@staticmethod=20(m=C3=A9todos=20est=C3=A1ticos)?= =?UTF-8?q?=20s=C3=A3o=20in=C3=BAteis=20em=20Python=20=3D)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula129.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 aula129.py diff --git a/aula129.py b/aula129.py new file mode 100644 index 0000000..c8cfea6 --- /dev/null +++ b/aula129.py @@ -0,0 +1,20 @@ +# @staticmethod (métodos estáticos) são inúteis em Python =) +# Métodos estáticos são métodos que estão dentro da +# classe, mas não tem acesso ao self nem ao cls. +# Em resumo, são funções que existem dentro da sua +# classe. +class Classe: + @staticmethod + def funcao_que_esta_na_classe(*args, **kwargs): + print('Oi', args, kwargs) + + +def funcao(*args, **kwargs): + print('Oi', args, kwargs) + + +c1 = Classe() +c1.funcao_que_esta_na_classe(1, 2, 3) +funcao(1, 2, 3) +Classe.funcao_que_esta_na_classe(nomeado=1) +funcao(nomeado=1)