-2
print(exec("5 + 5"))

its not printing 10 but prints None instead. I'm sure exec basically executes a code.

  • 2
    `exec` returns `None`. See the documentation for [**`exec`**](https://docs.python.org/3/library/functions.html#exec) – Peter Wood Nov 04 '20 at 12:05

1 Answers1

0

exec returns None. You should probably use the eval() in this case

Daniel
  • 487
  • 4
  • 11
  • 1
    Why do Python beginners alway come up with `eval`? Please read: [Eval really is dangerous](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html) – Matthias Nov 04 '20 at 12:18
  • Yeah, I wouldn't learn early about eval neither, I just answered the question – Daniel Nov 04 '20 at 12:33