Return Statements and Parentheses
This was originally posted on my old blog on the 24th of February, 2008
I've been trying to come up with an argument as to why you shouldn't be using parentheses around your return statements in Python for a few minutes, and I got it. Consider:
>>> def myfunc():
... return(1)
...
>>> myfunc()
1
Above is the classic example of people treating the return statement as a function. This could go bad, consider:
>>> def myfunc():
... return()
...
>>> myfunc()
()
An empty parenthesis pair is the literal for empty tuples in Python, which I find is a good reason, beyond aesthetics.
Comments
