Product Code Database
Example Keywords: winter -gran $49-182
barcode-scavenger
   » » Wiki: Docstring
Tag Wiki 'Docstring'.
Tag

A docstring is a that annotates an associated section of . It provides for the same utility as a comment, but unlike a comment is a string literal and is retained as part of the running program. Some development tools display docstring information as part of an interactive .

Programming languages that support docstring include Python, Lisp, Elixir, , Gherkin, Julia and Haskell. Tools that leverage docstring text include cobra-doc (Cobra), (Python), (Python), Sphinx (Python).


Examples

Elixir
Documentation is supported at language level, in the form of docstrings. is Elixir's de facto of choice for use in docstrings: def module MyModule do
 @moduledoc """
 Documentation for my module. With **formatting**.
 """
     

 @doc "Hello"
 def world do
   "World"
 end
     
end


Lisp
In Lisp, a docstring is known as a documentation string. The standard states that a particular implementation may choose to discard docstrings. When they are kept, docstrings may be viewed and changed using the DOCUMENTATION function. CLHS: Standard Generic Function DOCUMENTATION... For instance:
(defun foo () "hi there" nil)
(documentation #'foo 'function) => "hi there"
     


Python
In Python, a docstring is a string literal that follows a module, class or function definition. It must be nothing but a string literal, not any other kind of expression. The docstring is accessible via the associated code element's __doc__ attribute and the help function.

The following Python code declares docstrings for each program element:

"""The module's docstring"""

class MyClass:

   """The class's docstring"""
     

   def my_method(self):
       """The method's docstring"""
     

If saved as , the following is an interactive session showing how the docstrings may be accessed:

>>> import mymodule >>> help(mymodule) The module's docstring >>> help(mymodule.MyClass) The class's docstring >>> help(mymodule.MyClass.my_method) The method's docstring


See also
  • Source code comment formatted for automated documentation generation


External links

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs