×

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

Python Dictionary update() method

Python Dictionary update() method The dictionary.update() method in Python inserts the specified items to the dictionary. Syntax dictionary.update(iterable) Parameter iterable- This parameter represents a dictionary or an iterable object with key value pairs, that will...

1 minute read.

Cross Entropy in Python

Introduction Cross-entropy loss is frequently combined with the softmax function. Determine the total entropy among the distributions or the cross-entropy, which is the difference between two probability distributions. For the purpose...

5 minutes read.

What is Python compiler GDB?

The source code of one programming language is converted into machine code, bytecode, or another programming language by a compiler, a specialised software. A compiler is a tool that converts high-level...

3 minutes read.

Text detection using Tkinter in Python

Tkinter: The standard Python technique for building Graphical User Interfaces (GUIs) is Tkinter, which is included in all popular Python distributions. The only framework included in the Python standard library is...

4 minutes read.

Defaultdict in Python

In this tutorial, we will study What is defaultdict in Python We will understand it with the aid of certain examples. Before this, we will have a look at dictionaries...

3 minutes read.

Python Dictionary copy() method

Python Dictionary copy() method The dictionary.copy () method in Python returns a copy of the specified dictionary. Syntax dictionary.copy () Parameter NA Return None Example 1 # Python program explaining # the dictionary.copy() method # initialising the dictionary ...

1 minute read.

Adding item to a python dictionary

The dictionary is one of python’s built-in data structures where it stores key-value pairs. A dictionary is a collection of ordered values that can be changeable. We can add, modify,...

3 minutes read.

Python Read CSV file

The CSV stands for “comma-separated value,” which is defined as a simple file format that is used to store data into a tabular form such as a database or spreadsheet. It is...

7 minutes read.

Python PyMOTW

The cmd module comprises one class of the general public, Cmd, meant for command processors such interactive shells and other command interpreters as a foundation class. It utilises readline as...

3 minutes read.

Check whether dir is empty or not in python

Python: Check if a directory is empty In this tutorial, we will study how to check whether the director (dir) is empty or not in the python programming language. First of...

3 minutes read.

Python Seaborn

Seaborn is an open-source library in Python that is used for data visualization and plotting graphs. The plots are used for the Visualization of data. It is built on top...

10 minutes read.

Python String Lowercase

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 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 List Size

Introduction The list data type in Python is an ordered, flexible collection. A list may also contain duplicate entries. To get the size of any object, use the len() function in...

6 minutes 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 if statement

Python if statement Decision making is an essential feature of any programming languages. Condition checking is the strength of decision making. Python provides many decision-making statements, such as: If statementIf-else statementelif statement if statement The if statement is...

2 minutes read.

Exclusive OR in Python

In Python, the exclusive OR (XOR) operator is represented by the caret symbol (^). It compares each bit of the first operand to the corresponding bit of the second operand,...

3 minutes read.

Iterate a Dictionary in Python – Part 2

In this tutorial, we will learn above various methods used to Iterate a Dictionary in Python. Dictionary: In Python, a dictionary is an unordered collection of data values that is used to...

3 minutes read.

Python Indentation

Overview The spaces at the start of a code line are known as an indentation in Python programming. Indentation is only used for readability in other programming languages like C, C++,...

8 minutes read.

Python Win32 Process

The Win32 process is essentially a Python procedure. This program provides access to advanced Win32 process creation and management features. Process objects are created through the Create method (the constructor)....

6 minutes read.