Bryson mentioned Docstrings in the latest episode of the MacAdmins Podcast. But how do you use them? Documentation strings (or docstrings for short) are an easy way to document Python objects (classes, functions, methods, and modules in-line with your code. Docstrings are created using three double-quotes in the first
statement of the definition and are meant to describe in a human readable way what the object does.
Let’s look at an example for hello_krypted:def hello_krypted():
Docstrings can then be accessed using the __doc__ attribute on objects (e.g. via print):
"""This simply echos Hello Krypted.
But there's so much potential to do more!
""">>> print hello_krypted.__doc__
For more on docstrings, check out the official docs at https://www.python.org/dev/peps/pep-0257/
This simply echos Hello Krypted.
But you can say hello in person!
The post Define Docstrings in Python appeared first on krypted.com.
This post first appeared on Krypted.com | Tiny Deathstars Of Foulness, please read the originial post: here