GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Comments in Python Programming| Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Python Programming Tutorial
  • Python Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Typecasting
  • Operators in Python
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Identity Operators
    • Membership Operators
    • Operator Precedence
  • Input and Output in Python
    • Environment Setup
    • print() Function
    • input() Function
    • Comments
  • Decision Making in Python
    • Decision Making
    • if Statement
    • if else Statement
    • if elif Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Python
    • Loops
    • for Loop
    • while Loop
  • String in Python
    • String
    • String Methods
  • Built-in Data Structures in Python
    • Lists
    • Tuples
    • Sets
    • Dictionaries
  • Arrays in Python
    • Arrays
  • Searching in Python
    • Linear Search
    • Binary Search
  • Sorting in Python
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Python
    • Function
    • Recursive Function
    • Lambda Function
    • Closures
    • Decorators
    • Generators
  • OOPs in Python
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Class Variables
    • Static Methods
    • Inheritance
    • Types of Inheritance
    • MRO
    • Polymorphism
    • Abstract Classes
  • User-Defined Data Structures in Python
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Modules in Python
    • Modules
    • Time Module
    • Datetime Module
    • OS Module
    • Shutil Module
    • Sys Module
    • JSON Module
    • Random Module
  • Regular Expression in Python
    • Regular Expression
  • Exceptions in Python
    • Exception Handling
  • File Handling in Python
    • Text File Handling
    • Binary File Handling
    • CSV File Handling

bookmark
Table of Contents

    Comments in Python Programming

    In this lesson, we will understand what comments are and how it works in Python programming with the help of some examples.

    What are Comments

    In Python program Comments are portions of the code ignored by the interpreter which allow the user to make simple notes in the relevant areas of the source code.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    Comments in Python programming are used to provide information about lines of code. It is widely used for documenting code.

    Let's look at some examples to understand this better.

    Example 1 (Single Line Comments)
    # Printing Hello World on the screen.
    print("Hello World")  # Now we are going to print Hello World.
    Output
    Hello World

    In the first line, we used a single-line comment to explain what we are going to do in the next line. You can also write a comment at the end of a statement, as shown in the second line.

    Example 2 (Multi-Line Comment)
    # In this program we will learn how
    # to print Hello World on the screen
    print("Hello World")
    # print("\nThis is a Python tutorial")
    Output
    Hello World

    From the 1st line to the 2nd line, we used multi-line comments to explain what the program is about. You can also comment on any statement that you don't want to execute but want to keep for future reference, as shown in the 4th line.

    Python does not have a specific syntax for multi-line comments. To comment on multiple lines, we must place the # symbol at the beginning of each line, as shown in the example.

    However, a common trick is to use a multi-line string for comments. The Python interpreter will not execute the multi-line string unless it is assigned to a variable. Let's look at an example to understand this better.

    Example (Use of Multi-Line String as Multi-line Comment)
    """ In this program we will learn how
    to print Hello World on the screen """
    print("Hello World")
    

    Here you can see that we have used multi-line string to implement it as a multi-line comment. We can use either triple single quotes (''') or triple double quotes (""") to define a multi-line string. In between the opening and closing triple quotes, we will implement our multi-line comments as shown in the example above.


    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.