What is One Line & Multi Line Docstring in Python | EP-47 Docstring in Python Part 2 | Python Videos
4. One-line Docstrings
""" As the name suggests, one-line docstrings fit in one line.
They are used in obvious cases. The closing quotes are on the same line as the opening quotes. This looks better for one-liners."""
def power(a,b):
' ' 'Returns arg1 raised to power arg2.' ' '
print(a**b)
return a**b
print(power.__doc__)
power(5,6)
5. Multi-line Docstrings
""" Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. The summary line maybe on the same line as the opening quotes or on the next line."""
def add_numbers(a,b):
"""
This function takes two numbers as input and returns their sum.
Parameters:
a (int): The first number.
b (int): The second number.
Returns:
int: The sum of a and b.
"""
return a+b
print(add_numbers(3,5))
print(add_numbers.__doc__)
#PythonTutorial #DocstringsInPython #PythonForBeginners #PythonCode #CodingTips #OneLineDocstring #MultiLineDocstring #LearnPython #PythonVideos #CodeDocumentation #PythonProgramming #Python #Docstrings #Programming #Tutorial #Coding #PythonTips #SoftwareDevelopment #Developer
Connect With Us:
—————————————
➡ ️ Websitehttps://www.cybrosys.com/m/
➡ ️ Email: info@cybrosys.com
➡ ️ Twihttps://twitter.com/cybrosysosys
➡ ️ Lihttps://www.linkedin.com/company/cybrosys/brosys
➡ ️ https://www.facebook.com/cybrosystechnologiesnologies
➡ ️ https://www.instagram.com/cybrosystech/brosystech
➡ https://pinterest.com/cybrosys/ / cybrosys