Comment starts with the symbol in Python
Python programming language:
Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way. The python language can also be used in web development; Django and Flask are the frameworks used to create web applications using Python. In Python, indentation is the main concept; if we do not follow proper indentation, then the program will not run properly, and we will get an error in the output. The flask framework is the updated form of the Django framework; these two frameworks are used for creating web applications, mobile applications and desktop applications. Django is the open-source and free framework available in the python programming language for creating applications. The python programming language provides various libraries and modules which help complete the process faster. To perform any operations in the python programming language, first, we need to install the python interpreter on our computer. We need to install the python package installer ( pip ) to import any libraries or functions in Python. The python programming language also provides us with comments; these comments help the user understand the program more easily.
Comments in Python:
The comments in the python programming language are used to understand the code more easily. The interpreter will neglect these comments during the execution of the program. The user writes the comments to understand each line of the code more easily and carefully. The program's readability becomes easy with the help of these comments; we can easily understand why the programmer or user used a specific line of code or specific function in the program with the help of the comments. With the help of these comments, the user can easily explain the code to other developers. These comments are imported using the ‘#’ symbol; when we write any sentence after the ‘#’ symbol, the python interpreter will directly ignore the total sentence. These comments are enclosed in the single quotes or the triple quotes. Generally, the multiple-line comments are included in the triple quotes. The comments are generally divided into two types:
- Single line comments
- Multiple line comments
Single-line comments:
The single-line comment starts with the hashtag symbol (#). All the text written after the symbol will be considered comments. These comments are neglected by the python interpreter while executing the code. The single-line comments will exist only in a single line; if the comment exceeds more than one line, we need to add another hashtag symbol to display the comment. Through these comments, we can easily understand the usage of the corresponding variable, function and declarations. Now let us consider an example to understand the single-line comments.
Program:
# Creating a variable “class” to store the data
Class = ' Python class '
# displaying the data stored in the variable using the print function
print( Class )
Output:
Python class
Here we can observe that the comment started with the hashtag ( # ) symbol, written only in a single line, and all the text is written after the interpreter neglects the hashtag symbol after running the code.
Multiple line comments:
The comment is considered a multiple-line comment if we use more than a single line to describe the variable or function. Then, it is considered a multiple-line comment. Generally, multiple-line comments are written between the triple quotes, and if we use the hashtag symbol (#) multiple times, it is also considered a multiple-line comment. Now let us consider the two different examples of multiple-line comments:
Example: Multiple line comment using hashtags ( # )
# Creation of variable to store the data
# The variable stores the “python class” as the data
Class = " Python class "
# displaying the data stored in the variable using the print function
print( Class )
Output:
Python class
Here, we can observe that for the multiple line comments, we have used the symbol multiple times for displaying the numerous line comments.
Example: Multiple line comment using hashtags ( # )
''' Creation of variable to store the data
The variable stores the “python class” as the data '''
Class = “ Python class ”
# displaying the data stored in the variable using the print function
print( Class )
Output:
Python class
Here, we have used the string literals to display the multiple-line comments. Generally, we use triple quotes for displaying the multiple-line comments.