Skip to content

Commit 35d64fa

Browse files
author
charlesnoamlael
committed
criado e removido atributo dinâmico de objetos do tipo pessoa
1 parent e2eb100 commit 35d64fa

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

oo/pessoa.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,31 @@
2121

2222
# ATRIBUTOS COMPLEXO
2323

24+
# class Pessoa():
25+
# def __init__(self, *filhos, nome=None, idade=35):
26+
# self.nome = nome
27+
# self.idade = idade
28+
# self.filhos = list(filhos)
29+
#
30+
#
31+
# def cumprimentar(self):
32+
# return f'Olá {id(self)}'
33+
#
34+
#
35+
# if __name__ == '__main__':
36+
# renzo = Pessoa(nome='Renzo')
37+
# luciano = Pessoa(renzo, nome='Luciano')
38+
# print(Pessoa.cumprimentar(luciano))
39+
# print(id(luciano))
40+
# print(luciano.cumprimentar())
41+
# print(luciano.nome)
42+
# print(luciano.idade)
43+
# for filho in luciano.filhos:
44+
# print(filho.nome)
45+
46+
47+
# ATRIBUTO DINAMICO
48+
2449
class Pessoa():
2550
def __init__(self, *filhos, nome=None, idade=35):
2651
self.nome = nome
@@ -42,6 +67,12 @@ def cumprimentar(self):
4267
print(luciano.idade)
4368
for filho in luciano.filhos:
4469
print(filho.nome)
70+
luciano.sobrenome = 'Ramanlho' # Criação do atributo dinâmico fazendo a atribuição
71+
del luciano.filhos # Remoção do atributo
72+
print(luciano.__dict__) # Os atributos de instancia ficam presentes no __dict__
73+
print(renzo.__dict__)
74+
75+
4576

4677

4778

0 commit comments

Comments
 (0)