Regarding the "standard" way to put comments inside Python source code:
def func(): "Func doc" ... <code> 'TODO: fix this' #badFunc() ... <more code> def func(): "Func doc" ... <code> #TODO: fix this #badFunc() ... <more code>
I prefer to write general comments as strings instead of prefixing #'s. The official Python style guide doesn't mention using strings as comments (If I didn't miss it while reading it).
I like it that way mainly because I think the #
character looks ugly with comment blocks. As far as I know these strings don't do anything.
Are there disadvantages in doing this?
Don't misuse strings (no-op statements) as comments. Docstrings, e.g. the first string in a module, class or function, are special and definitely recommended.
Note that docstrings are documentation, and documentation and comments are two different things!
Documentation is read by people who use your code, comments by people who want to understand your code, e.g. to maintain it.
Using strings for commentation has the following (potential) disadvantages:
Most important for Python programmers: It is not pythonic:
There should be one—and preferably only one—obvious way to do it.
Stick to the standards, use comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With