Skip to content

Commit de85dd7

Browse files
committed
Atributo complexo filhos
1 parent a35eae4 commit de85dd7

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

oo/pessoa.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
class Pessoa:
2-
def __init__(self, nome=None, idade=47):
2+
def __init__(self, nome=None, idade=47, *filhos):
33
self.nome = nome
44
self.idade = idade
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('Itiro')
12-
print(Pessoa.cumprimentar(p))
13-
print(id(p))
14-
print(p.cumprimentar())
15-
print(p.nome)
16-
p.nome = 'Alexandre'
17-
print(p.nome)
12+
alex = Pessoa(nome='Alex')
13+
itiro = Pessoa('Itiro', 47, alex)
14+
print(Pessoa.cumprimentar(itiro))
15+
print(id(itiro))
16+
print(itiro.cumprimentar())
17+
print(itiro.nome)
18+
for filho in itiro.filhos:
19+
print(filho.nome)

0 commit comments

Comments
 (0)