Comments and Docstrings

Hello Techies!!

What are comments ?

Comments are used to remind yourself and to inform others about the function of your program. Multi line comments are used for large text descriptions of code or to comment out chunks of code while debugging applications. Comments are ignored by the compiler.

Debugging is the process of identifying and removing errors from your code.

To write a single line comment in python we use # in front of the line.

# add function – used to add two numbers
def add(a, b):
return a+b

This will help us to know what this function is doing and also compiler will not execute the commented part of the code. It is informative part of your code.

If you want to write multi-line comment, then use ”’ — your comment goes here — ”’.

function – add
parameters – a , b
returns – addition of two numbers
def add(a, b):
return a+b

This is how you make your code informative, readable and easier for others to understand. It will also help you when you come back and read your code after few years without remembering what it was about.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.