Skip to content
Advertisement

Python3 exec, why returns None?

When the code below this text, and returns the result None why?

JavaScript

Result:

JavaScript

Module code exx.py:

JavaScript

Advertisement

Answer

The problem of course is not only that print returns None, it is that exec returns None, always.

JavaScript

If you’d need the return value, you’d use eval:

JavaScript

after which you’d notice that print still returns None

Advertisement