From 02ae0a48b0e27da8eade6b5cace00a7be6a6f75b Mon Sep 17 00:00:00 2001 From: Luan Carvalho Date: Mon, 25 Feb 2019 13:34:24 -0300 Subject: [PATCH 1/5] =?UTF-8?q?Criando=20m=C3=A9todo=20cumprimentar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/__init__.py | 0 oo/pessoa.py | 9 +++++++++ 2 files changed, 9 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..33e328873 --- /dev/null +++ b/oo/pessoa.py @@ -0,0 +1,9 @@ +class Pessoa: + def cumprimentar(self): + return f'Olá {id(self)}' + +if __name__=='__main__': + p = Pessoa() + print(Pessoa.cumprimentar(p)) + print(id(p)) + print(p.cumprimentar()) From d7495e177bfe2cd1d95bea0921e6505134504f29 Mon Sep 17 00:00:00 2001 From: Luan Carvalho Date: Mon, 25 Feb 2019 13:41:41 -0300 Subject: [PATCH 2/5] Criado atributos de instancia nome e idade. --- oo/pessoa.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 33e328873..a022a88cd 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,9 +1,16 @@ class Pessoa: + def __init__(self, nome=None, idade=35): + self.nome = nome + self.idade = idade + def cumprimentar(self): return f'Olá {id(self)}' if __name__=='__main__': - p = Pessoa() + p = Pessoa('Luan') print(Pessoa.cumprimentar(p)) print(id(p)) print(p.cumprimentar()) + print(p.nome) + print(p.idade) + From 95ac687b63d68642907fb24ee673ab77aca7a6a0 Mon Sep 17 00:00:00 2001 From: Luan Carvalho Date: Mon, 25 Feb 2019 13:45:42 -0300 Subject: [PATCH 3/5] Criado atributo complexo filhos. --- oo/pessoa.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index a022a88cd..9b841da1f 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,16 +1,19 @@ class Pessoa: - def __init__(self, nome=None, idade=35): + def __init__(self, *filhos, nome=None, idade=35): self.nome = nome self.idade = idade + self.filhos = list(filhos) def cumprimentar(self): return f'Olá {id(self)}' if __name__=='__main__': - p = Pessoa('Luan') + renzo = Pessoa(nome='Renzo') + p = Pessoa(renzo, nome='Luan') print(Pessoa.cumprimentar(p)) print(id(p)) print(p.cumprimentar()) print(p.nome) - print(p.idade) + for filho in p.filhos: + print(filho.nome) From 84659a3af9797c1ab650191ef36fb8783a27975d Mon Sep 17 00:00:00 2001 From: Luan Carvalho Date: Mon, 25 Feb 2019 13:51:55 -0300 Subject: [PATCH 4/5] =?UTF-8?q?Criado=20e=20removido=20atribudo=20din?= =?UTF-8?q?=C3=A2mico=20do=20objeto=20Pessoa.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oo/pessoa.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/oo/pessoa.py b/oo/pessoa.py index 9b841da1f..8560564b5 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -16,4 +16,8 @@ def cumprimentar(self): print(p.nome) for filho in p.filhos: print(filho.nome) + p.sobrenome = 'Carvalho' + del p.idade + print(p.__dict__) + print(renzo.__dict__) From 7c8974830657c1e1c5c4dc70800c5f9c43be2784 Mon Sep 17 00:00:00 2001 From: Luan Carvalho Date: Mon, 25 Feb 2019 14:01:34 -0300 Subject: [PATCH 5/5] Criado atributo de classe olhos. --- oo/pessoa.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oo/pessoa.py b/oo/pessoa.py index 8560564b5..4c38169aa 100644 --- a/oo/pessoa.py +++ b/oo/pessoa.py @@ -1,4 +1,6 @@ class Pessoa: + olhos = 2 + def __init__(self, *filhos, nome=None, idade=35): self.nome = nome self.idade = idade @@ -18,6 +20,12 @@ def cumprimentar(self): print(filho.nome) p.sobrenome = 'Carvalho' del p.idade + p.olhos = 1 + del p.olhos print(p.__dict__) print(renzo.__dict__) - + Pessoa.olhos = 3 + print(Pessoa.olhos) + print(p.olhos) + print(renzo.olhos) + print(id(Pessoa.olhos), id(p.olhos), id(renzo.olhos))