python string math

print eval('2 + 4')
# or
d = eval('4 * 5')
print d

Here is what the above code is Doing:
1. It’s creating a string that contains the Python expression ‘2 + 4’.
2. It’s passing that string to the eval() function.
3. The eval() function evaluates the string as if it were a Python expression, and returns the result.
4. The result is assigned to the variable d.
5. The print statement displays the value of d.