How to comment in python.

narendrapalacharla
1 min readApr 19, 2022

Commenting on your code is good practice if you want to help people or for the future you to understand what you’ve written today.

#This is a comment!

It is extremely simple to comment on the python code, Just we need to add a hashtag before the line. So that the interpreter will ignore those lines.

Inline comments can be useful, But placing them will make it hard to read the code.

Some common and useful captions to add to your code include:

  • A little bit about any new function and what it does
  • An explanation of what a variable or set of variables is for
  • Explaining why you have done something a certain way (if it is not obvious)
  • Highlighting key and important parts of your code
  • Providing warnings

Some useful tips for keeping comments helpful rather than distracting:

  • Keep comments succinct and no longer than necessary — be respectful of your reader’s time!
  • Avoid comments that state the obvious; don’t over a comment.
  • Don’t just explain what something does: explain why you put it there and why it’s important
  • Be polite and friendly! Absolutely do not use comments to shame other coders. That’s a quick way to become the least popular person on your team.

The main use for learning how to comment in Python is to provide useful guidance and instruction. This can help others navigate code. That said though, there are other scenarios where using code can be useful.

Due credits to android authority.

--

--