Followers

Wednesday, 22 July 2020

Tips for Adding Comments in Python

Tips for Adding Comments in Python






Python is a high-level programming language that can be used for developing GUI applications, websites, and web applications. Python codes are already very easy to understand, but if you add some comments to it, then it will add some context to what you have done with the coding. This will help other people know or understand the coding that you have written. The primary purpose of the comment is to provide useful instructions to the readers and to help them navigate the codes.


Others need to understand what you point precisely through your comments. A creator can add comments to explain what their code does. They should feel free to define every direction and outlooks surrounding that code. At times, people know how to write codes for Python, but they get confused when it comes to commenting. In this article, we are going to solve all your issues related to comments in Python.

How to add comments?

Just like coding, commenting is also easy in Python. In Python, you will always have to add ‘hashtags’ as a prefix for everything you type. Adding a comment will not bring any changes to your coding; however, using a hashtag is necessary. A hashtag has the power to get the comment ignored by the interpreter, and at the same time, it will highlight the code for the viewers.

Make sure that you always keep your comments below 79 characters per line. There is no fixed rule for the 79 characters, but it will be more helpful for the readers as they won’t have to scroll back and forth to read the whole comment. And, one general rule is that you should never place in-line comments consecutively or else it can get hard to differentiate between the code and comment.

When should we add a comment?

You must add a comment every time you want to explain a particular point or function elaborately to the readers. And, always publish readable comments. Your comments or captions should explain a set of variables and their functions. Creators can also insert warnings, highlights, key points, or explanations for why they have coded something a certain way, etc. in their comments. But there are also some points that you should remember to prevent your comments from being distracting.

  • Do not over comment on the codings.
  • Your comments should have a polite and respectful undertone.
  • Do not mock or shame other creators.
  • Keep your comments brief and clear.

Using all the points mentioned above in both the sections will help you create good comments for your codes, the next time you use Python. The Python comments can also help the readers to find their way throughout the code using the search tools. Your comments should always serve a higher purpose for the readers. To make your entire content look more elegant and readable, make sure that you name the variables and functions smartly.


Source:-  Adding Comments in Python


No comments:

Post a Comment

My Hero Academia: Who Is Better Between Overhaul and Shoto Todoroki?

  My Hero Academia has several heroes that are powerful enough to rival the strongest protagonists of Shonen anime. Even the prestigious U.A...