Skip to content

Commit e2eb100

Browse files
author
charlesnoamlael
committed
criado atributo complexo filhos
1 parent e484638 commit e2eb100

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

oo/pessoa.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1+
# class Pessoa():
2+
# def __init__(self, nome=None, idade=35):
3+
# self.nome = nome
4+
# self.idade = idade
5+
#
6+
#
7+
# def cumprimentar(self):
8+
# return f'Olá {id(self)}'
9+
#
10+
#
11+
# if __name__ == '__main__':
12+
# p = Pessoa('Luciano')
13+
# print(Pessoa.cumprimentar(p))
14+
# print(id(p))
15+
# print(p.cumprimentar())
16+
# print(p.nome)
17+
# p.nome = 'charles'
18+
# print(p.nome)
19+
# print(p.idade)
20+
21+
22+
# ATRIBUTOS COMPLEXO
23+
124
class Pessoa():
2-
def __init__(self, nome=None, idade=35):
25+
def __init__(self, *filhos, nome=None, idade=35):
326
self.nome = nome
427
self.idade = idade
28+
self.filhos = list(filhos)
529

630

731
def cumprimentar(self):
832
return f'Olá {id(self)}'
933

1034

1135
if __name__ == '__main__':
12-
p = Pessoa('Luciano')
13-
print(Pessoa.cumprimentar(p))
14-
print(id(p))
15-
print(p.cumprimentar())
16-
print(p.nome)
17-
p.nome = 'charles'
18-
print(p.nome)
19-
print(p.idade)
36+
renzo = Pessoa(nome='Renzo')
37+
luciano = Pessoa(renzo, nome='Luciano')
38+
print(Pessoa.cumprimentar(luciano))
39+
print(id(luciano))
40+
print(luciano.cumprimentar())
41+
print(luciano.nome)
42+
print(luciano.idade)
43+
for filho in luciano.filhos:
44+
print(filho.nome)
2045

2146

2247

0 commit comments

Comments
 (0)