File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
2449class 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
You can’t perform that action at this time.
0 commit comments