3/28/25, 4:13 PM Python Comments
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Python Comments
❮ Previous Next ❯
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:
Example Get your own Python Server
#This is a comment
print("Hello, World!")
Try it Yourself »
Comments can be placed at the end of a line, and Python will ignore the rest of the line:
Example
https://www.w3schools.com/python/python_comments.asp 1/6
3/28/25, 4:13 PM Python Comments
print("Hello,
Tutorials
World!") #This is a comment
Exercises Services Sign Up Log in
HTML
Try itCSS
YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO W3.CSS C
A comment does not have to be text that explains the code, it can also be used to
prevent Python from executing code:
Example
#print("Hello, World!")
print("Cheers, Mate!")
Try it Yourself »
Multiline Comments
Python does not really have a syntax for multiline comments.
To add a multiline comment you could insert a # for each line:
Example
#This is a comment
#written in
#more than just one line
print("Hello, World!")
Try it Yourself »
Or, not quite as intended, you can use a multiline string.
https://www.w3schools.com/python/python_comments.asp 2/6
3/28/25, 4:13 PM Python Comments
Since Python will ignore string literals that are not assigned to a variable, you can add a
multilineTutorials
string (tripleExercises Services
quotes)in your comment inside
code, and place your Signit:
Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")
Try it Yourself »
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.
?
Exercise
Which character is used to define a Python comment:
'
//
/*
Submit Answer »
https://www.w3schools.com/python/python_comments.asp 3/6
3/28/25, 4:13 PM Python Comments
Tutorials Video:
Exercises Python
Services Comments
Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
❮ Previous Next ❯
Track your progress - it's free! Sign Up Log in
https://www.w3schools.com/python/python_comments.asp 4/6
3/28/25, 4:13 PM Python Comments
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
COLOR PICKER
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
https://www.w3schools.com/python/python_comments.asp 5/6
3/28/25, 4:13 PM Python Comments
HTML Tutorial
Tutorials CSS Tutorial
Exercises
JavaScript Tutorial
Services Sign Up Log in
How To Tutorial
HTML
CSS SQL Tutorial SQL
JAVASCRIPT PYTHON JAVA PHP HOW TO W3.CSS C
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.
https://www.w3schools.com/python/python_comments.asp 6/6