comments in python

What is comments in Python?

Comments in Python are lines of text that are written in the code but are not executed by the Python interpreter. These comments are used to provide information and explain what the code does. They are meant for human readers, such as other programmers or yourself, to better understand the code.

There are Two types of comments in python are given below.

  1. Single-line comments 
  2. Multi-line comments
Single line Comments:

Single line comments in Python are brief explanations or clarifications that occupy only one line of code and are indicated by the hash symbol (#). They are used to make the code more readable and understandable, and are ignored by the Python interpreter.

Example:

# this is a single line comment
print("Hello world")

print("Hello world")# this is a single line comment

# print("Hello world")
print("Hello world")

Multiline Comments:

Multiline comments in Python are comments that span across multiple lines of code and are used to provide detailed explanations or documentation for functions, classes, or modules. They are indicated by a set of triple quotes (""") at the beginning and end of the comment block.

Example:

""" This is a multiline comment. It can span across multiple lines of code. Multiline comments are often used to provide detailed explanations or documentation for functions, classes, or modules. """
print("Hello world")