Multi-line docstrings

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Sat Dec 23 06:21:13 EST 2006


The Python docs recommend the use of triple-quoted string literals for
docstrings, e.g.

    def Meet(Alice, Bob) :
        """arranges a meeting between Alice and Bob.
        Returns a reference to the meeting booking object."""
        ...
    #end Meet

However, these tend to get messed up by indentation whitespace, which gets
spuriously included as part of the string.

Another possibility is to use implicit concatenation of string literals,
e.g.

    def Meet(Alice, Bob) :
        "arranges a meeting between Alice and Bob." \
        " Returns a reference to the meeting booking object."
        ...
    #end Meet

This includes no spurious whitespace, or even any newlines; if you want
these, you must put them explicitly in the string:

    def Meet(Alice, Bob) :
        "arranges a meeting between Alice and Bob.\n" \
        "Returns a reference to the meeting booking object."
        ...
    #end Meet




More information about the Python-list mailing list