• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / How to Create Block and Multi-Line Comments in Python

How to Create Block and Multi-Line Comments in Python

October 6, 2022 Leave a Comment

To create a block comment in Python, you just need to add # before each line – just like you would for a regular single line comment.

# This is a valid block comment
# Here is some more commentary
# And finally some more information

You can also use triple quotes to create multi-line comment in Python. Triple quotes create a multi-line string in Python.

'''

Here is a block comment with some text in Python

'''

When programming, comments are fundamental to helping make your code readable and helps provide context to components of your code.

One such kind of comment which is useful is the block comment.

Block comments are used to provide descriptions of files, classes, and functions. Block comments are commonly used at the beginning o files and before functions.

To create a block comment in Python, you just need to add # before each line – just like you would for a regular single line comment.

# This is a valid block comment
# Here is some more commentary
# And finally some more information

Another way you can create a block comment is with a multi-line string literal.

While this isn’t true comment, it can work like a comment in your Python code.

You can also use triple quotes to create multi-line comment in Python.

Below shows you how you can create a multi-line string literal in your Python code.

'''

Here is a block comment with some text in Python

'''

Hopefully this article has been useful for you to learn how to create block comments and multi-line comments in your Python code.

Other Articles You'll Also Like:

  • 1.  Remove Substring from String in Python with replace()
  • 2.  Fibonacci Sequence in Python with for Loop
  • 3.  Get Length of File Using Python
  • 4.  Create List of Numbers from 1 to 100 Using Python
  • 5.  Using Python to Calculate Average of List of Numbers
  • 6.  Check if Variable is Datetime in Python
  • 7.  Repeat String with * Operator in Python
  • 8.  Using Python to Convert Integer to String with Leading Zeros
  • 9.  Using Python to Read File Word by Word
  • 10.  Using Python to Remove Commas from String

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy