Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Single Set of Double Quotes for Python Comments?

While reviewing some code used in the online CS188.1x class on edX.org (code written by the instructors), I noticed the repeated use of a single set of double quotes (like one might use around a str) for use as comments.

I haven't seen this before, nor is it mentioned in PEP8 that I could find, but it certainly seems to work fine. Can anyone enlighten me?

Here's 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's a normal inline comment

    def bar(self, item):
        "Here is another example of the comment style"
       return wtf
like image 952
Brian W. Avatar asked Oct 14 '12 18:10

Brian W.


People also ask

Does Python use single quotes or double quotes?

Use single-quotes for string literals, e.g. 'my-identifier' , but use double-quotes for strings that are likely to contain single-quote characters as part of the string itself (such as error messages, or any strings containing natural language), e.g. "You've got an error!" .

What is single set double quotes?

If you use single quote marks, you should use double speech marks for a quote within a quote. If you use double quote signs, you should use single quotation signs for a quote within a quote. Examples: "When I say 'immediately,' I mean sometime before August," said the manager.

What does double quotes do in Python?

What are double quotes in Python used for? A double quotation mark is to set off a direct (word-for-word) quotation. For example – “I hope you will be here,” he said. In Python Programming, we use Double Quotes for string representation.


1 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 preferred to use the triple quote format to allow for longer, better formatted docstrings, and to call attention to them for easy reference, but any string will qualify.

Docstrings are distinct from comments because comments are not relevant to the execution of a program at all, whereas docstrings are available at runtime by accessing an object's __doc__ variable.

like image 107
Andrew Gorcester Avatar answered Oct 08 '22 18:10

Andrew Gorcester