Say "I want to make an equation and store it as a string", how am I able to later on "remove" the apostrophes and thereby solve the problem?
# example of generated equation
equation = "5 + 2 * 9"
# now solve it somehow
solution = int(equation)
Say "I want to make an equation and store it as a string", how am I able to later on "remove" the apostrophes and thereby solve the problem?
# example of generated equation
equation = "5 + 2 * 9"
# now solve it somehow
solution = int(equation)
equation = '5 + 2 * 9'
solution = int(eval(equation))
print(solution)
As Austin pointed out in the comments above, eval has certain limitations and security issues as, in brief, it can be used to execute arbitrary code. This should not be used if the user is being prompted to input an equation, or if an external entity otherwise might be able to influence the expression being evaluated.
See Austin's link : Eval Caveats and Dangers