Documenting a Function in Python: DOCSTRING in Python - Python Tutorial for Beginners

preview_player
Показать описание
🎓 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:

#Python #Tutorial #Beginners #Shorts

***

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

***

♡ FOLLOW US ♡

♡ SUPPORT US ♡

***
Рекомендации по теме
Комментарии
Автор

How to document your Function with Docstring? 🤔

DigitalAcademyOnline
Автор

Nice tutorial I want to python tutorial A to Z Step by Step.

jahidhosain
join shbcf.ru