Documenting a Function in Python: DOCSTRING in Python

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ Documenting your Code in Python: Docstring in Python

Although optional, documentation is a good programming practice – especially if you want to get your dreamed job at Google, Apple, Facebook or anywhere in the World! Plus, unless you can remember what you had for dinner last week, always documenting your code will help you a lot when you will need to stay away for a while, then come back.

You can attach documentation in Python to a function definition by including a string literal called docstring, just after the function header. It is briefly used to explain what a function does.


○ What is a Docstring in Python?

A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object.

Note: Docstrings in Python are usually triple quoted, to allow for multi-line descriptions.


○ Documenting your Code in Python: Docstrings in Python

def hello():
"""This function prints
message on the screen"""
print('Hello, World!')



○ Print Function Help (Rich format)

To print a function’s documentation, use the Python help() function and pass the function’s name as parameter.

help(hello)

# Help on function hello in module __main__:
# hello()
# This function prints
# message on the screen



○ Print Function Help (RAW format)

You can also access the docstring in Python through __doc__ attribute of the function.

print(hello.__doc__)
# OUTPUT: This function prints message on the screen



Let’s play this video, stick around and watch until the end of this video! 👍🏻

– Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho

☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw

📖 Blog: http://digital.academy.free.fr/blog/

📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners

🛒 Shopping and Discounts: http://digital.academy.free.fr/store

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
http://digital.academy.free.fr/
https://twitter.com/DigitalAcademyy
https://www.facebook.com/digitalacademyfr
https://www.instagram.com/digital_academy_fr/
https://www.youtube.com/c/DigitalAcademyOnline

♡ SUPPORT US ♡
http://digital.academy.free.fr/join
http://digital.academy.free.fr/donate
http://digital.academy.free.fr/subscribe
https://www.patreon.com/digital_academy
https://www.buymeacoffee.com/digital_academy

***

Copy link
Powered by Social Snap