v.0.7.5 SimpleCounter

This commit is contained in:
tiijay
2025-11-15 13:57:51 +01:00
parent c7855e3fcc
commit 4459a2f648
4 changed files with 57 additions and 11 deletions

View File

@@ -0,0 +1,39 @@
class SimpleCounter:
_value: int
def __init__(self):
self._value = 0
@property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = value
# Arithmetic operators
def __add__(self, other):
return self._value + other
def __sub__(self, other):
return self._value - other
# In-place operators
def __iadd__(self, other):
self._value += other
return self
def __isub__(self, other):
self._value -= other
return self
# Conversion and representation
def __int__(self):
return self._value
def __str__(self):
return str(self._value)
def __repr__(self):
return f"SimpleCounter(value={self._value})"