From 3eb3e562d0cb1b9bc9fe55593e151a4ecd43c2a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Mon, 14 Nov 2022 09:20:42 -0300 Subject: [PATCH] =?UTF-8?q?=5F=5Fdict=5F=5F=20e=20vars=20para=20atributos?= =?UTF-8?q?=20de=20inst=C3=A2ncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula126.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 aula126.py diff --git a/aula126.py b/aula126.py new file mode 100644 index 0000000..2203290 --- /dev/null +++ b/aula126.py @@ -0,0 +1,25 @@ +# __dict__ e vars para atributos de instância +class Pessoa: + ano_atual = 2022 + + def __init__(self, nome, idade): + self.nome = nome + self.idade = idade + + def get_ano_nascimento(self): + return Pessoa.ano_atual - self.idade + + +dados = {'nome': 'João', 'idade': 35} +p1 = Pessoa(**dados) +# p1.nome = 'EITA' +# print(p1.idade) +# p1.__dict__['outra'] = 'coisa' +# p1.__dict__['nome'] = 'EITA' +# del p1.__dict__['nome'] +# print(p1.__dict__) +# print(vars(p1)) +# print(p1.outra) +# print(p1.nome) +print(vars(p1)) +print(p1.nome)