Skip to content

Commit ce250e4

Browse files
author
renzon
committed
Criado atributo complexo filhos
1 parent 1332e4e commit ce250e4

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

oo/pessoa.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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

1011
if __name__ == '__main__':
11-
p = Pessoa('Luciano')
12-
print(Pessoa.cumprimentar(p))
13-
print(id(p))
14-
print(p.cumprimentar())
15-
print(p.nome)
16-
p.nome = 'Renzo'
17-
print(p.nome)
18-
print(p.idade)
12+
renzo = Pessoa(nome='Renzo')
13+
luciano = Pessoa(renzo, nome='Luciano')
14+
print(Pessoa.cumprimentar(luciano))
15+
print(id(luciano))
16+
print(luciano.cumprimentar())
17+
print(luciano.nome)
18+
print(luciano.idade)
19+
for filho in luciano.filhos:
20+
print(filho.nome)

0 commit comments

Comments
 (0)