Nov-03-2022, 06:31 PM
private variable implies a class. Python has classes. Python classes are just like C# classes. Here is a Python class based on your original post.
class SomeClass: def __init__(self, m, s, t, y, z=0): self.m = m self.s = s self.t = t self.y = y self._z = z @property def z(self): f = (self.m - 5) / (self.m - self._z) sm = self.s / f fi = sm + self.t self._z = fi / self.y return self._z @z.setter def z(self, value): self._z = value thing = SomeClass(1, 2, 3, 4) print(thing.z, thing.z, thing.z) thing.y = 2 thing.z = 0 print(thing.z, thing.z, thing.z)
Output:0.625 0.703125 0.712890625
1.25 1.5625 1.640625
As you can see from the output. z changes value each time it is accessed. Also demonstrated is how you can change attributes of the object (values used in the equations) from outside the class.