This content originally appeared on DEV Community and was authored by Aditi Sharma
Hello dev community
This is Day 2 of my Python learning journey. Today I focused on docstrings—something small but very powerful in writing clean and professional code.
What are Docstrings?
Docstrings are string literals that appear right after the definition of a function, class, or module.
They explain what the code does and act as in-code documentation.
Think of docstrings as a “manual” for your functions.
Why Use Docstrings?
Improve code readability
Help others (and future you) understand code faster
Work with tools like
help()
and IDE hintsMake collaboration easier in bigger projects
Coding Practice
python
def greet(name):
"""Return a friendly greeting message for the given name."""
return f"Hello, {name}!"
print(greet("World"))
This content originally appeared on DEV Community and was authored by Aditi Sharma