From f32f89686f3e6ced05844eaa0411805d3ad633a6 Mon Sep 17 00:00:00 2001 From: Fabiano Date: Tue, 25 Feb 2020 00:28:38 -0300 Subject: [PATCH 1/5] Criada a classe Pessoa --- oo/__init__.py | 0 oo/pessoa.py | 2 ++ 2 files changed, 2 insertions(+) create mode 100644 oo/__init__.py create mode 100644 oo/pessoa.py diff --git a/oo/__init__.py b/oo/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/oo/pessoa.py b/oo/pessoa.py new file mode 100644 index 000000000..e1da50e22 --- /dev/null +++ b/oo/pessoa.py @@ -0,0 +1,2 @@ +class Pessoa: + pass \ No newline at end of file From 72fc765fabb5544ac848cc67dceafaff9f163692 Mon Sep 17 00:00:00 2001 From: Fabiano Date: Tue, 25 Feb 2020 00:41:02 -0300 Subject: [PATCH 2/5] =?UTF-8?q?Criada=20m=C3=A9todo=20complementar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index e1da50e22..923520597 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,2 +1,9 @@ class Pessoa: - pass \ No newline at end of file + def cumprimentar(self): + return f'Olá {id(self)}' + +if __name__ == '__main__': + p = Pessoa() + print(Pessoa.cumprimentar(p)) + print(id(p)) + print(p.cumprimentar()) \ No newline at end of file From a87f1e69b187dba0b899f700f60759c028707a6c Mon Sep 17 00:00:00 2001 From: Fabiano Date: Tue, 25 Feb 2020 16:20:01 -0300 Subject: [PATCH 3/5] Criado atributo filhos --- oo/pessoa.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 923520597..d62882588 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,9 +1,20 @@ class Pessoa: + def __init__(self, *filhos, nome=None, idade=35): + self.idade = idade + self.nome = nome + self.filhos = list(filhos) + def cumprimentar(self): return f'Olá {id(self)}' if __name__ == '__main__': - p = Pessoa() - print(Pessoa.cumprimentar(p)) - print(id(p)) - print(p.cumprimentar()) \ No newline at end of file + renzo = Pessoa(nome='Renzo') + luciano = Pessoa(renzo, nome='Luciano') + print(Pessoa.cumprimentar(luciano)) + print(id(luciano)) + print(luciano.cumprimentar()) + print(luciano.nome) + print(luciano.idade) + for filho in luciano.filhos: + print(luciano.nome) + From 5c196c0cef3daa832c046398a45d6069f6bb29ad Mon Sep 17 00:00:00 2001 From: Fabiano Date: Wed, 26 Feb 2020 00:12:18 -0300 Subject: [PATCH 4/5] Criado e removido atributo filhos --- oo/pessoa.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index d62882588..792502428 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -9,7 +9,7 @@ def cumprimentar(self): if __name__ == '__main__': renzo = Pessoa(nome='Renzo') - luciano = Pessoa(renzo, nome='Luciano') + luciano = Pessoa(renzo, nome='Fabiano') print(Pessoa.cumprimentar(luciano)) print(id(luciano)) print(luciano.cumprimentar()) @@ -17,4 +17,10 @@ def cumprimentar(self): print(luciano.idade) for filho in luciano.filhos: print(luciano.nome) + luciano.sobrenome = 'Figueiredo' + print(luciano.sobrenome) + del luciano.filhos + + print(luciano.__dict__) + print(renzo.__dict__) From e4994869cca8250fe0e8e6ea16eef41178d70762 Mon Sep 17 00:00:00 2001 From: Fabiano Date: Wed, 26 Feb 2020 00:45:17 -0300 Subject: [PATCH 5/5] =?UTF-8?q?criando=20m=C3=A9todo=20de=20classe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/oo/pessoa.py b/oo/pessoa.py index 792502428..9a02bc2a2 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -7,6 +7,14 @@ def __init__(self, *filhos, nome=None, idade=35): def cumprimentar(self): return f'Olá {id(self)}' + @staticmethod + def metodo_estatico(): + return 42 + + @classmethod + def nome_e_atributos_de_classe(cls): + return f'{cls} - olhos {cls.olhos}' + if __name__ == '__main__': renzo = Pessoa(nome='Renzo') luciano = Pessoa(renzo, nome='Fabiano') @@ -24,3 +32,11 @@ def cumprimentar(self): print(luciano.__dict__) print(renzo.__dict__) + Pessoa.olhos = 3 + print(Pessoa.olhos) + print(luciano.olhos) + print(renzo.olhos) + print(id(Pessoa.olhos),id(luciano.olhos),id(renzo.olhos)) + print(Pessoa.metodo_estatico(),luciano.metodo_estatico()) + print(Pessoa.nome_e_atributos_de_classe(),luciano.nome_e_atributos_de_classe()) +