Comments in functions


Is there a specific reason that comments inside of functions use triple quotes (""") rather than the hashtag (#)? As far as I could see from my testing using # doesn’t impact the code at all. In fact, the only difference I could see what with regards to coloring in the code editor.

I first came across this in this exercise.


Triple quotes create strings, those are not comments

Strings placed in certain places get picked up and added to that object’s attributes which can be used by documentation tools or looked up directly from within python

>>> def f():
...     'does all the things'
>>> help(f)
Help on function f in module __main__:

    does all the things