Docstrings and Comments
Last updated
What is Docstrings and Comments?
Docstrings and comments document what code does and why. A docstring is a string literal placed right after a function, class, or module definition, and it becomes accessible through the object's doc attribute, which tools use to generate documentation automatically. Comments, marked with #, explain specific lines or blocks of code and are ignored by the interpreter. Docstrings typically describe the purpose, parameters, and return value of a function, while comments clarify tricky logic or note reasons behind a particular implementation choice.
Free resources to learn Docstrings and Comments
- Official docsDocstring Conventions
- ArticlePython Comments
More in stage 1: Learn the Basics
Docstrings and Comments: common questions
Can I learn Docstrings and Comments in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Docstrings and Comments in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Docstrings and Comments tutorial for beginners?
It is lesson 9 of 85 in the free Python roadmap, in stage 1, Learn the Basics. If you are new to Python, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.