+ 2
How does eval function work?
Could someone explain why the 'eval' computes in this way? https://code.sololearn.com/cU6ion3RJGzL/?ref=app
2 Respostas
+ 9
It calculates your mathematical expression within the PEMDAS rules, so in the following order: Parentheses, Exponentiation, Multiplication, Division, Addition and Substraction.
1**2**3 gets resolved to 1, as 1**2 equals 1 and then 1**3... still one :)
0
Vladimir, eval is very interesting function ))) In a few words: It executes its argument like it has printed in console. For example eval("1+2+3*4") returns 15 (imagine that you've typed >>>1+2+3*4 and pressed Enter). So print(eval("1+2+3*4")) outputs 15 in console.