24

Was going through a Python tutorial, but it seems kinda dated. Wanted to know if people regularly use docstrings in the workforce. Or are they somewhat irrelevant because you can convey most of that info via comments and context? Do jobs make you use them?

you are viewing a single comment's thread
view the rest of the comments
[-] Michal@programming.dev 2 points 1 week ago* (last edited 1 week ago)

Docstrings are important and their role is different than comments. They give an overview how the function works, explain parameters and sometimes give examples how to use them. You can generate documentation using sphinx from Docstrings, and as others said IDEs use docstrings to show you information about function you're using.

Comments are just text that gets ignored by interpreter. You can add explanation to code if it's not self explanatory, but they're not useful outside of the immediate area being commented on.

Other languages also have documentation options that is separate from comments, e.g. JavaDoc. The syntax is usually similar to coment, but slightly different to differentiate it from comments (extra * in multiline comment).

this post was submitted on 05 Apr 2025
24 points (92.9% liked)

Python

7006 readers
14 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS