Comments in Python

basic of python,

Sourabh Somani Sourabh Somani Follow Apr 05, 2018 · 1 min read
Share this

Introduction

In this tutorial we will learn about the python comments and we will also know about types of comments in the python.

What are Comments?

Comments play a very important role in the maintenance of the program. It explicates what’s actually happening inside a program. when we place comments inside the source code, it enhances the readability and understanding of the code.

Comments do not affect the execution speed and the size of the compiled program. Python Interpreter ignores the comment.

Python permits two types of comments, namely

  • Single-line Comments
  • Multi-line Comments

Single-line comments

It begins with a hash (#) symbol and terminates at the end of the line.

Example

# This is a single line comment
# Adding two numbers (2 and 3)
print(2+3)

Multi-line Comment

If we want to put comments in more then one line we can use hash(#) beginning of every line.

Example

# Hey folks
# We can place the hash symbol in 
# beginning of the each line
# To extends comments to multiple line 

There is one more way to do the same, using triple quotes either ‘’’ or “””

Example

"""Here is the 
best example to write
multi-line comments"""
Join Newsletter
Get the latest news right in your inbox. We never spam!
Sourabh Somani
Written by Sourabh Somani Follow
Sourabh Somani is a Full-Stack Engineer with several years of hands-on experience. He has been awarded 4-times Microsoft MVP award consecutively and C# Corner MVP Award 6-times. Most of the time you will find him helping people on C# Corner and StackOverflow on JavaScript, .NET and Python. He is a frequent contributor to open source software development via forums, articles, and blogs. He regularly speaks at user groups and developer conferences. His core technology interests are JavaScript, Python and .NET.