This cookie is set by GDPR Cookie Consent plugin. These cookies ensure basic functionalities and security features of the website, anonymously. Necessary cookies are absolutely essential for the website to function properly. Help on function multiplier in module _main_:
print this comment: print(multiplier._doc_)įunction returns multiplication result of its inputsĪnd here is how we can use the help() function fo access docstring comments: help(multiplier) ' function returns multiplication result of its inputs ' Here is how we can access the docstring comment by calling the _ doc_ method: multiplier._doc_ We can call the _doc_ method of the object.We can access docstring comments in two ways: """ function returns multiplication result of its inputs """ Here is an example: def multiplier(par1,par2): They are implemented with triple quotes (“”” “””). In Python, docstring comments are also used to describe classes and methods.ĭocstring comments have to be declared right after the function, class or method declaration. what its effect is, rather than describing its internal procedures and decision making. More precisely, docstring comments are used to describe and document what a function does – i.e. By convention, docstring comments are used to document functions. Let us quickly test the function: multiplier(a,b)ĭocstring comments are another type of Python comments. This function takes two input parameters, multiplies them and returns the result
I show this in the example below: """ FUNCTION DESCRIPTION: Multi-line Python comments can be implemented with “”” “””. # this comment could describe what the variables below represent This is demonstrated in the example below. In Python, single-line comments can be implemented with the # operator. There are three ways of commenting Python code:
This post provides a quick tutorial on how to comment Python code.