Skip to content

Commit b51427c

Browse files
m41b3cm41b3c
authored andcommitted
Criado método de classe.
1 parent 1fe0ca8 commit b51427c

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

OO/pessoa.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def __init__(self, *filhos, nome=None, idade=35):
1010
def cumprimentar(self):
1111
return f'Olá {id(self)}'
1212

13+
#metodos de Classe
14+
@staticmethod
15+
def metodo_estatico():
16+
return 42
17+
18+
@classmethod
19+
def nome_e_atributos_de_classe(cls):
20+
return f'{cls} - olhos {cls.olhos}'
1321

1422
if __name__ == '__main__':
1523
sofia = Pessoa(nome='Sofia')
@@ -34,11 +42,22 @@ def cumprimentar(self):
3442
del jacir.sobrenome
3543
print(jacir.__dict__)
3644

45+
#teste atributos de classe
46+
3747
print(Pessoa.olhos)
3848
print(jacir.olhos)
3949
jacir.olhos = 3
4050
print(jacir.__dict__)
4151

52+
#teste metodos de classe
53+
54+
print(id(Pessoa.olhos), id(jacir.olhos))
55+
print(Pessoa.metodo_estatico(), jacir.metodo_estatico())
56+
print(Pessoa.nome_e_atributos_de_classe(), jacir.nome_e_atributos_de_classe())
57+
58+
59+
60+
4261

4362

4463

0 commit comments

Comments
 (0)