Skip to content

Commit e4f7a8c

Browse files
Criado atributo complexo filhos
1 parent d53effa commit e4f7a8c

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

oo/pessoa.py

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

6-
def cumprimentar(self):
7-
return f'Olá {id(self)}'
7+
def cumprimentar(self): # Metódo da Classe
8+
return f'Olá {id(self)}' # O método executa alguma coisa.
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)
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+
for filho in luciano.filhos:
18+
print(filho.nome)
19+

0 commit comments

Comments
 (0)