As mention use data stucture eg a @dataclass() is a simple way.
from dataclasses import dataclass
@dataclass()
class Var:
x: float
y: float
z: int = 1
var = Var(1.5, 2.5)
print(var)
Output:
Var(x=1.5, y=2.5, z=1)
So data is mutable and can change as wish.
If want it immutable just add
@dataclass(frozen=True)
.
>>> var.x = 100.4
>>> var.x
100.4
>>> var
Var(x=100.4, y=2.5, z=1)
The data is also stored in dictionary,to see this can call like this.
>>> var.__dict__
{'x': 100.4, 'y': 2.5, 'z': 1}
Just to clarify this is this same as making variables like this.
>>> x = 100.4
>>> y = 2.5
>>> z = 1
Now will these variables go into
globals
dictionary,as Gribouillis show some examples of.
But should not mess with
globals
and use normal visible data structure as eg shown here.
If you unfamiliar with dataclass,here is the same as a ordinary class.
class Var:
def __init__(self, x: float, y: float, z: int = 1):
self.x = x
self.y = y
self.z = z
def __repr__(self):
return f"Var(x={self.x}, y={self.y}, z={self.z})"
var = Var(1.5, 2.5)
print(var)
Output:
Var(x=1.5, y=2.5, z=1)