Skip to content

Commit 05d1eef

Browse files
m41b3cm41b3c
authored andcommitted
Criado atributos complexos filhos.
1 parent 6baf75e commit 05d1eef

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

OO/pessoa.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
class Pessoa:
2-
def __init__(self, nome=None, idade=35):
2+
def __init__(self, *filhos, nome=None, idade=35):
33
self.idade = idade
44
self.nome = nome
5+
self.filhos = list(filhos)
56

67
def cumprimentar(self):
78
return f'Olá {id(self)}'
89

910

1011
if __name__ == '__main__':
11-
p = Pessoa('Jacir')
12-
print(Pessoa.cumprimentar(p))
13-
print(id(p))
14-
print(p.cumprimentar())
15-
print(p.nome)
16-
p.nome = 'Pieniak'
17-
print(p.nome)
18-
print(p.idade)
12+
sofia = Pessoa(nome='Sofia')
13+
valentina = Pessoa(nome="Valentina")
14+
jacir = Pessoa(sofia, nome='Jacir')
15+
jacir = Pessoa(valentina, nome = 'Jacir')
16+
print(Pessoa.cumprimentar(jacir))
17+
print(id(jacir))
18+
print(jacir.cumprimentar())
19+
print(jacir.nome)
20+
21+
for filho in jacir.filhos:
22+
print(filho.nome)

0 commit comments

Comments
 (0)