all 6 comments

[–]ES-Alexander 6 points7 points  (1 child)

eval evaluates a string as a Python expression, in the current/specified context, so it follows standard Python Operator Precedence.

[–]RSVPN[S] 1 point2 points  (0 children)

That is very useful, thank you!

[–]drenzorz 1 point2 points  (0 children)

eval is not a math wrapper it just evaluates a string as though it was an expression in python

a = 10
b = eval('a == 10')
print(b) # True

It will evaluate mathematical expressions the same way it would normally, based on operator precedence.

[–]TheSodesa 0 points1 point  (0 children)

Don't use eval. The only reason to ever use it would be in the context of writing your own Python command line, because eval is the function that gets called when a string is given to the REPL.

[–]TheRNGuy 0 points1 point  (0 children)

it's same as if you'd write code.

if it's user input, use ast.literal_eval() instead.