Skip to content

Commit b8c66c7

Browse files
committed
Criado atributo complexo filhos
1 parent 1ca2c8b commit b8c66c7

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

oo/pessoa.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
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
if __name__ == '__main__':
10-
p = Pessoa('Luciano')
11-
print(Pessoa.cumprimentar(p))
12-
print(id(p))
13-
print(p.cumprimentar())
14-
print(p.nome)
15-
p.nome = 'Cliver'
16-
print(p.nome)
17-
print(p.idade)
11+
cliver = Pessoa(nome='cliver')
12+
luciano = Pessoa(cliver, nome='luciano')
13+
print(Pessoa.cumprimentar(luciano))
14+
print(id(luciano))
15+
print(luciano.cumprimentar())
16+
print(luciano.nome)
17+
print(luciano.idade)
18+
for filho in luciano.filhos:
19+
print(filho.nome)
20+

0 commit comments

Comments
 (0)