I'm looking for a way, to calculate strings, that might include variables. eval
won't do the job, as I want to use undefined variables. I'm talking about a function, that would turn "2*3*x"
to "6*x"
for example.
Is there a function for that?
I'm looking for a way, to calculate strings, that might include variables. eval
won't do the job, as I want to use undefined variables. I'm talking about a function, that would turn "2*3*x"
to "6*x"
for example.
Is there a function for that?
You could use sympy for symbolic computation:
To convert rationals to floats, use
sy.nfloat
: