Comments in python or any programming language are assumed to be non-readable parts of any program by the compiler/interpreter.
Comments are used to explain any code, make the code more readable, and prevent execution when testing code.
There are two types of comments:
- Single-Line Comments
- Multi-line Comments
1. Single-Line Comments in Python
Single line comments start with “#” and can be used anywhere in a program, see the example below
# This is a single line comment in Python print("We are learning comments in Python") print("Nothing") # This is an inline comment
We are learning comments in Python Nothing
2. Multi-Line Comments in Python
In python, single quotes(‘) and double quotes(“) represents the same meaning.
If you put anything inside a multiline string(triple quotes) anywhere in your code then that will be called multiline comments, see the example below.
print("Example of multiline comments") """This is a multiline comment in python """ '''This is also a multiline comment in python with the help of single quotes '''
Example of multiline comments
- Make money with Python in 2022
- Top 15 Python Libraries For Data Science in 2022
- Top 15 Python Libraries For Machine Learning in 2022
- File Explorer in Python using Tkinter
- Drawing Application in Python Tkinter
- Sequel Programming Languages(SQL)
- Run Python Code, Install Libraries, Create a Virtual Environment | VS Code
- Ticket selling in Cricket Stadium using Python | Assignment Expert