When attempting to evaluate expressions like eval("2")
, the result is an integer. However, evaluating a print expression yields a None type. The print command is executed, but eval("print(2+3)")
returns None.
This is because the print() function is being called within eval()
:
eval("(2 +3)")
In this case, the eval()
function returns the value 5, which is then printed out. However, when you use:
print(eval("print(2 +3)"))
The eval()
function is only evaluating the inner print statement, which prints the value 5. The eval()
function itself does not return a value, so the outer print statement prints None.