diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/resources/tags/docstring.md | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bot/resources/tags/docstring.md b/bot/resources/tags/docstring.md new file mode 100644 index 000000000..cf5413f4b --- /dev/null +++ b/bot/resources/tags/docstring.md @@ -0,0 +1,20 @@ +A [`docstring`](https://docs.python.org/3/glossary.html#term-docstring) is a string with triple quotes that often used in file, classes, functions, etc. A docstring usually has clear explanation (such as what the function do, purposes of the function, and other details of the function), parameter(s) and a return type. + +Here's an example of a docstring: +```py +def greet(name, age) -> str: + """ + Greet someone with their name and age. + + :param name: The name to greet. + :type name: str + :param age: The age to display. + :type age: int + :return: String of the greeting. + """ + return_string = f"Hello, {name} you are {age} years old!" + return return_string +``` +You can get the docstring by using `.__doc__` attribute. For the last example you can get it through: `print(greet.__doc__)`. + +For more details about what docstring is and it's usage check out [https://realpython.com/documenting-python-code/#docstrings-background](realpython) or [https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring](official PEP docs). |