How are docstring different from comments?

 

Answer:

Docstrings

Comments

They are used to describe functions and classes and show what parameters they accept and what they return.

They are used to explain the working of a code and sometimes to exclude a bit of code without removing it.

The docstring of a certain method or class can be viewed using the help( ) function.

Not visible while executing the code.

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.