Convert String To Calculable Operation
Is it possible to convert string to a calculable operation I want to make this done: >>> import math >>> operation = '10/2*6 + math.sqrt(42)' >>> compute
Solution 1:
eval
will do that for you.
>>> import math
>>> operation = "10/2*6 + math.sqrt(42)"
>>> eval(operation)
36.48074069840786
Post a Comment for "Convert String To Calculable Operation"