How to evaluate a mathematical expression within a string in Python

Evaluating a mathematical expression in a string returns the computation performed by parsing the characters of the string as mathematical operators. For example, evaluating the expression within “2 + 2 / 3” returns 2.6666666666666665.

Solution for How to evaluate a mathematical expression within a string in Python : You can use eval() to evaluate a mathematical expression within a string Call eval(source) with the expression string as source to return the resulting computation.


how-to-evaluate-a-mathematical-expression-within-a-string-in-python