How To Write Comments In Python

The way you think is reflected in programming in order to convey the individual steps that you took to solve an issue utilizing a computer. Commenting your code helps clarify your thinking process, which in turn makes it easier for you and other people to comprehend the purpose of your code in the future. Because of this, you will have an easier time locating bugs, fixing them, enhancing the code at a later time, and reusing it in other applications as well.

The act of commenting is essential to the completion of any and all tasks, regardless of how little, medium, or fairly enormous they may be. It should be considered standard procedure for software engineers since it is an important component of your workflow. Without comments, things have the potential to get quite complicated very quickly. In this post, we will cover the many techniques of commenting that Python offers, as well as how it may be utilized to automatically produce documentation for your code via the use of the so-called module-level docstrings.

It is easy to overlook your thinking process later on, therefore comments made afterward may be less beneficial in the long run, thus it is generally a good idea to write comments as you are developing or updating a program. This is because it is easier to ignore your thought process later on.

Read: How to Create an executable from a Python program

Prerequisites

You need to ensure that Python 3 is installed and that a programming environment is prepared on the computer or server that you are using. You may consult the installation and setup procedures for a local programming environment or for a programming environment on your server that is suitable for your operating system if you do not yet have a programming environment set up (Ubuntu, CentOS, Debian, etc.)

Comment Syntax

Python comments are denoted by the combination of a hash mark (#) and a whitespace character, and they extend all the way to the line’s end.

The majority of the time, comments will seem somewhat like this:

OUTPUT:

Comment code in python / Comment line in python

Read: 6 Reasons why you Should Learn Python

Because comments are not meant to be executed, you will not see any sign of the remark when you run a program since comments are not meant to be executed. Comments are included in the source code for humans to read and not for computers to carry out the instructions there.

 


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Marianne elanotta

As a graduate in communication technologies, Marianne likes to share the latest technological advances in various fields. She likes to program in Java OO and Javascript and prefers to work on Open source operating systems. She likes to play chess and computer games in her spare time along with her 2 kids.

Leave a Reply