Python Comments

JK JK 2018 
Created at
Updated at  
7,536 0 0

Comments can be used to explain Python code.

Comments can be used to make the code more readable.

Comments can be used to prevent execution when testing code.


Creating a Comment

Comments starts with a #, and Python will ignore them:

#This is a comment
print("Hello, World!")

Comments can be placed at the end of a line, and Python will ignore the rest of the line:

print("Hello, World!") #This is a comment

A comment does not have to be text that explains the code, it can also be used to prevent Python from executing code:

#print("Hello, World!")
print("Cheers, Mate!")

Multiline Comments

Python does not really have a syntax for multiline comments.

To add a multiline comment, you could insert a # for each line:

#This is a comment
#written in
#more than just one line
print("Hello, World!")

Or, not quite as intended, you can use a multiline string.

Since Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:

"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")

As long as the string is not assigned to a variable, Python will read the code, but then ignore it, and you have made a multiline comment.

 

Tags Multiline Comments Python Python Comments Python Multiline Comments Facebook X
Comments 0
Similar posts
  1. Python Syntax
    7,405
  2. Python Variables
    7,396
  3. Python Getting Started
    7,454
  4. Python Introduction
    7,100
  5. What is Python?
    7,728
  6. Python Data Types
    7,436
  7. Python String Operations
    7,407
  8. Python Lists
    7,336
  9. String concatenation by join()
    7,132
  10. Printing string n times
    7,065
  11. Python Arithmetic Operators
    7,075
  12. Python Comparison Operators
    7,238
  13. Python Tuples
    7,165
  14. Python Sets
    7,091
  15. Python Dictionaries
    7,054
  16. Python Conditions and If statements
    7,128
  17. Python While Loops/For Loops
    7,504
  18. Python Functions
    7,062
  19. Python Lambda
    7,102
  20. Python Arrays
    7,086
  21. Python Classes/Objects
    7,466
  22. Python Inheritance
    7,188
  23. Python Iterators
    7,105
  24. Python Polymorphism
    7,086
  25. Python Scope
    7,062
  26. Python Modules
    7,099
  27. Code Chronicles - A Caffeine-Fueled Journey into Data Software Engineering
    7,361
  28. Machine Learning Types and Programming Languages
    7,232
  29. Python Tutorials for AP Computer Science Principles, Data Projects and High School Internship
    7,890
  30. Mastering Excel Data Manipulation with Python
    7,069
  31. Challenge: One Code Problem Per Day
    1,096
  32. Clean Python Environments: The Power of venv vs. Docker
    830
  1. Python Lambda
    7,102
  2. Python Functions
    7,062
  3. Python While Loops/For Loops
    7,504
  4. Python Conditions and If statements
    7,128
  5. Python Dictionaries
    7,054
  6. Python Sets
    7,091
  7. Python Tuples
    7,165
  8. Python Comparison Operators
    7,238
  9. Python Arithmetic Operators
    7,075
  10. Printing string n times
    7,065
  11. String concatenation by join()
    7,132
  12. Python Lists
    7,336
  13. Python String Operations
    7,407
  14. Python Data Types
    7,436
  15. Python Variables
    7,396
  16. Python Syntax
    7,405
  17. Python Getting Started
    7,454
  18. Python Introduction
    7,100
  19. What is Python?
    7,728
Recently updated
  1. Watch This Dazzling Dancer’s Mind-Blowing Moves
    58
  2. Michael Jackson's Billie Jean
    139
  3. Bootstrap vs. Tailwind CSS: Origins, Features, Pros & Cons, and How to Choose the Right Framework
    143
  4. The Complete Guide to Golang: History, Features, Real-World Uses, and Code Examples
    439
  5. Telemetry vs. Analytics: Understanding the Difference and Why It Matters
    241
  6. The Evolution and Production Reality of Agentic AI
    216
  7. How to Activate or Waive Your UIUC Student Health Insurance
    303
  8. Complete Guide to Building a Machine Learning Model
    328
  9. My life cuts at Las Vegas during Thanksgiving day holiday
    7,413
  10. The Cybercab Transformation: From Autonomous Taxi to Mobile Base Station
    355
  11. Harness vs. OpenClaw: Two Very Different "Agents"
    984
  12. Clean Python Environments: The Power of venv vs. Docker
    830
  13. What is Docker? Why is Docker also useful in a development environment?
    625
  14. UIUC 2026-2027 Academic Calendar
    1,603
  15. How to Build Llama 3 AI Apps with Python: Setup & User Prompts
    812
  16. Open-Source LLMs: The AI Revolution
    764
  17. Resume 2.0: Leveling Up for My First Software Gig
    2,236
  18. Not everyone will understand what this man just did
    1,893
  19. UIUC Dorm Guide: Find Your Perfect Fit !!
    1,599
  20. Unpacking IU's Shopper
    771
  21. Jackie Chan's Police Story: The Action Masterpiece
    667
  22. The IVE Story: Identity, 'I AM' Charts, and Influence
    970
  23. Tech Visionaries who graduated at UIUC - You are the Next Turn
    1,191
  24. Open Databases for Sex Crime Occurrences in the U.S.
    720
  25. Automatically copy text to the clipboard when dragging the mouse in the Cursor
    2,659
  26. My First Day at University of Illinois-Urvana Champaign
    1,199
  27. Sand, Sea, and a Splash of Fun at Newport Beach: A Family Adventure
    8,138
  28. Sun, Rocks, and Adventure: A Day at Joshua Tree National Park
    8,220
  29. Sipping the Stars: My Starbucks Adventure
    9,666
  30. Exciting explore at Sequoia National Park
    7,667
  31. My Life Shot at Death Valley
    1,717
  32. Ip Man fights with Muay Thai Master
    944
  33. Mad Clown - Don't Die
    1,030
  34. How to get Student Enrollment and Degree Verification at UIUC
    4,919
  35. LAX Thanksgiving Rush: A Joyful Reunion
    927
  36. ZO ZAZZ(조째즈) - Don`t you know (모르시나요) (PROD.ROCOBERRY)
    1,135
  37. FISHINGIRLS Unleashes Energetic EP 'Funiverse' Featuring Signature Track 'Fishing King'
    988
  38. 10CM - To Reach You (너에게 닿기를)
    1,166
  39. Feeling weak? Transform yourself at the UIUC ARC!
    1,575
  40. BOYNEXTDOOR - If I Say I Love You
    1,192
  41. The Future of Software Engineer - AI Engineering
    934
  42. G Dragon x Taeyang (Eyes Nose Lips, Power, Home Sweet Home, GOOD BOY) - LE GALA PIÈCES JAUNES 2025
    925
  43. Lie - Legend song by BIGBANG
    7,821
  44. Why ROLLBACK is useful when you work with Google Gemini CLI?
    846
  45. Reimbursement after Vaccination at McKinley Health Center
    1,027
  46. Gemini CLI makes a Magic! Time to speed up your app development with Google Gemini CLI!
    970
  47. Common Questions from UIUC school life in terms of CS Program
    1,128
  48. UIUC Immunization Compliance
    1,217
  49. LEE CHANHYUK's songs really resonate with my soul - Time Stop! Vivid LaLa Love, Eve, Endangered Love ...
    1,101
  50. LEE CHANHYUK - Endangered Love (멸종위기사랑)
    1,097