DEV Community

Aditi Sharma
Aditi Sharma

Posted on

Day 2

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 hints
  • โœ… Make 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"))
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
suvrajeet profile image
Suvrajeet Banerjee

Docstring day! ๐Ÿ“