Skip to content

Commit

Permalink
1.13 - Implementação, decisões e assert
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuxbaum committed Mar 21, 2021
1 parent ad01fa4 commit 360580d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 1_introducao/13_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Nesta implementação em Java, o livro utiliza o artificio 'static' da linguagem.
Entretanto não há uma forma, em Python, para simular o comportamento de
atributos estáticos EXATAMENTE como ocorre em Java.
Para simular o comportamento em Python, o atributo estático deve ser acessado
diretamente por sua classe, e não pela instância (como é feito no livro).
"""


class A:

STATIC = int()

def __init__(self):
self.media = int()


a = A()
A.STATIC, a.STATIC, a.media = 5, 5, 5

b = A()
A.STATIC, b.STATIC, b.media = 7, 7, 7


assert (A.STATIC, a.STATIC, a.media, b.STATIC, b.media) == (7, 5, 5, 7, 7)

0 comments on commit 360580d

Please sign in to comment.