A single set of double quotes for Python comments?

When I looked at the code used in the CS188.1x online class on edX.org (code written by instructors), I noticed a repetition of using one set of double quotes (for example, can be used around str) to use as comments.

I have not seen this before and did not mention it in PEP8 , which I could find, but it seems to be working fine. Can anyone enlighten me?

Here is an example:

class SomeClass(): """ Some docstring info, using standard 'triple double quotes' """ def __init__(self): "This is the comment style to which I'm referring." some.code = foo # Here a normal inline comment def bar(self, item): "Here is another example of the comment style" return wtf 
+4
source share
2 answers

A docstring is any string literal that appears as the first statement in a class, method, function, or module. Stylistically, it’s typical and preferable to use a triple quote format, which allows you to use longer, better formatted docstrings and draw attention to them to simplify the links, but any string will match.

Docstrings are different from comments because comments are not related to program execution at all, while docstrings are available at run time by accessing the __doc__ object __doc__ .

+4
source

This is just a doctrine. This is a good design recommendation. For example, if you load this class into your python shell, you can call help(bar) and you will get "Here is another example of the comment style"

0
source

Source: https://habr.com/ru/post/1439671/


All Articles