I recently noticed something weird. I typed something like
exec code
And I obviously got an error. What is interesting is the error description - SyntaxError: Missing parentheses in call to 'exec'. I haven't found any other function that would give similarly detailed one. If I have for example
eval code
I get SyntaxError: invalid syntax. All user-defined functions and all built-ins I found, e. g. min, filter, behave the same.
Why are these error messages inconsistent?
Since
exec codeis a valid syntax in Python 2 but not in Python 3, this error message is more detailed than a generalSyntaxErrorbecause it was (and is) very popular (well, as popular as the usage ofexec) when one is transitioning from Python 2 to Python 3.You get the exact error when trying to
print stringin Python 3 (as long asstringis defined of course).