×

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.


Related Topics

How to Make an App with Python

In this age of mobiles, rapid mobile application development has got a lot of traction. Moreover, app developers are high in demand because of the increase in digitization. Generally, Python is...

4 minutes read.

Python String

Python String Python string is considered as the most popular data type present in Python language. In Python, string data type is the collection of characters, letters, white spaces etc. written...

31 minutes read.

Sklearn in Python

Scikit-learn or sklearn is a machine learning library used in Python that provides many unsupervised and supervised learning tools and algorithms. David Cournapeau first created it as a 2007 Google...

7 minutes read.

Python Decorator

Python Decorator: A Decorator is an interesting feature of Python that helps the user design patterns and insert a new functionality to an existing object without making any modifications in...

6 minutes read.

Subprocess in Python

In this tutorial, we will understand what is a subprocess in python and will understand how to use it. Subprocess A subprocess is a very prevailing portion of the python library. It...

3 minutes read.

Write Text files in Python

Let's discuss writing the text file in detail. Generally, writing text also follows the same procedure as like reading text. It varies only in some specific places. Steps followed for writing...

4 minutes read.

Decision Tree in Python

Decision Tree is one of the most essential algorithms in the area of machine learning for classification and regression. But let us first talk about the lifespan of every machine learning...

12 minutes read.

Explain sklearn clustering in Python

Make a connection and patterns across datasets by using clustering, one of the unsupervised machine learning approaches. Grouping is crucial because it ensures unlabelled data's natural clustering. The sample from...

7 minutes read.

Python Lexicographic Order

Python lexicographic order Before we discuss the lexicographic order in Python, we should understandwhat is lexicographic order and sort according to lexicographic order. Lexicographic order In mathematics, the generalization of the alphabetical order...

5 minutes read.

How to create a dictionary in Python?

How to create a dictionary in python Dictionary is a data structure in Python that represents our data in the form of keys and values. Each value in a dictionary can be...

5 minutes read.

Python IDE

What is an IDE?  An IDE or an Integrated Development Environment is a type of software where developers can develop many software’s and applications and run the programs inside it. An...

11 minutes read.

Fsolve in Python

Python Programming Language Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

Python Os sep

Python: 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....

3 minutes read.

Python Set isdisjoint() method

Python Set isdisjoint() method The set.isdisjoint() method in Python returns a boolean value True if two sets are disjoint sets ( i.e. none of the elements are present in both sets), otherwise it returns...

1 minute read.

Python SciPy Library

Introduction SciPy, a logical library for Python is an open-source, BSD-authorized library for arithmetic, science, and design. The SciPy library relies upon NumPy, which gives advantageous and quick N-dimensional exhibit control....

6 minutes read.

Python Skyline

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...

3 minutes read.

Python map() function

Python map() function The map() function in Python returns an iterator that applies a function to every item of iterable, yielding the results. Syntax map(function, iterable, ...) Parameter function: It is a required parameter that represents the function to...

1 minute read.

Python Simple Interest

Python is an Object-Oriented high-level language. Python has an English-like syntax, which is very easy to read and write codes. Python is an interpreted language which means that it uses...

3 minutes read.

Speech Recognition Module in Python

Speech Module in Python: Converting text to speech, known as Speech Synthesis, this process is the computer-generated recreation of human speech. This module converts the human language text into human-like...

8 minutes read.

Google Python Class

Python: 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....

3 minutes read.