Skip to content

Commit d17693f

Browse files
committed
Atributos de instancia nome e idade
1 parent f50033f commit d17693f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

oo/pessoa.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
class Pessoa:
2+
def __init__(self, nome=None, idade=31):
3+
self.nome = nome
4+
self.idade = idade
5+
26
def cumprimentar(self):
37
return f'Olá {id(self)}'
48

59

610
if __name__ == "__main__":
7-
p = Pessoa()
11+
p = Pessoa('Francisco')
812
print(Pessoa.cumprimentar(p)) # desnecessário
913
print(id(p))
1014
print(p.cumprimentar()) # p passado implicitamente
15+
print(p.nome)
16+
p.nome = 'Francisco'
17+
print(p.idade)

0 commit comments

Comments
 (0)