Function docstring as a local variable

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jul 10 21:54:32 EDT 2011


On Mon, 11 Jul 2011 09:00 am Corey Richardson wrote:

> Excerpts from Colin J. Williams's message of Sun Jul 10 18:28:15 -0400
> 2011:
>> Try:
>> 
>> def f():
>>       ds= """docstring"""
>>       print ds
> 
> That doesn't actually make a docstring, though. It makes a string object
> and points the name ds at it. Do you know what a docstring is?


Colin might not be aware of why docstrings are useful, and arbitrary local
variables ds="""docstring""" are not.


def f1():
    """This is my documentation string.

    Imagine this has actual useful information.
    """

def f2():
    dc = """This is my documentation string.

    Imagine this has actual useful information.
    """


Now, at the interactive interpreter, call:

help(f1)
help(f2)



-- 
Steven




More information about the Python-list mailing list