would print each of the various documentation strings in this example. #!/usr/bin/env python # Example of using doc strings """My Doc-string example""" class Foo : '''Some documentation for the Foo class''' def _init_ ( self ): "Foo's initialization method's documentation" def bar (): """documentation for the bar function""" if _name_ = "_main_" : print ( _doc_ ) print ( Foo. These are called "documentation" strings or "docstrings" for short and they are automatically associated with the _doc_ attribute of the class, function, or module objects in which they are defined. Python makes pervasive use of strings which immediately follow class and function definition statements, and those which appear as the first non-blank, non-comment line in any module or program file. Using unassigned strings as comments is frowned on and may also trigger certain linters. Thus it's possible to "comment out" a section of code by simply wrapping the lines in "triple quotes" (three consecutive instances of quotation marks, or of apostrophes, and terminated with a matching set of the same). Note that strings inserted among program statements in Python are treated as expressions (which, in void context, do nothing). They also may span multiple lines without special escape characters. """Un-assigned strings in triple-quotes might be used as multi-line comments """ ''' "triple quoted strings" can be delimited by either 'single' or "double" quote marks and they can contain mixtures of other quote marks without any need to \escape\ them using any special characters. Like Brainf***, all characters and whitespace which are not commands are ignored.Īlso, since the code/data-space is two-dimensional, comments can be placed anywhere that will be untouched by the instruction pointer and data access commands.įinally, in Funge-98, the instruction immediately skips to the next instruction, which allows to isolate comments from code. With Extensions £ This is a hash/pound comment for a UK keyboard £
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |