Python Comments: Creating A Comment
Python Comments: Creating A Comment
Menu Log in
Dark mode
Dark code
HTML CSS
Python Comments
❮ Previous Next ❯
Creating a Comment
Comments starts with a # , and Python will ignore them:
Example
#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:
https://www.w3schools.com/python/python_comments.asp 1/7
5/18/22, 2:19 PM Python Comments
Example
Try it Yourself »
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 »
Example
#This is a comment
#written in
print("Hello, World!")
Try it Yourself »
https://www.w3schools.com/python/python_comments.asp 2/7
5/18/22, 2:19 PM Python Comments
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:
Example
"""
This is a comment
written in
"""
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:
Comments in Python are written with a special character, which one?
This is a comment
Submit Answer »
https://www.w3schools.com/python/python_comments.asp 3/7
5/18/22, 2:19 PM Python Comments
❮ Previous Next ❯
NEW
We just launched
W3Schools videos
Explore now
COLOR PICKER
Get certified
by completing
https://www.w3schools.com/python/python_comments.asp 4/7
5/18/22, 2:19 PM Python Comments
a course today!
school
w3 s
2
CE
02
TI 2
R
FI .
ED
Get started
CODE GAME
Play Game
Report Error
Forum
About
https://www.w3schools.com/python/python_comments.asp 5/7
5/18/22, 2:19 PM Python Comments
Shop
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
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
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Web Courses
HTML Course
CSS Course
JavaScript Course
https://www.w3schools.com/python/python_comments.asp 6/7
5/18/22, 2:19 PM Python Comments
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »
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.
https://www.w3schools.com/python/python_comments.asp 7/7