Comments are code inside a Python script that is not executed or run by the machine. Comments are only used to mark or provide written explanations in the script.
Comments are commonly used to let others understand what the script does, or to remind the programmer themselves if they edit the script again someday.
To use comments you simply write a hash sign # followed by your comment or by using string literals opened and closed with """.
Below are examples of using comments in Python:
#This is a comment
# This writing will not be executed
#comments with hash sign can only be used
#for
#one
#line
"""
Writing comments more than one line is
by using triple double quotes and
closed with triple double quotes too
"""
print("Hello World") #this is also a comment
#print("Welcome")
# comments can contain special characters !@#$%^&\*(),./;'[]\
#print name
print("Budi")
#print number/integer
print(123)
When you run the script above, you will see output in the form of Hello World, Budi and 123, because the writing/comments written are not executed.
Gabung Komunitas Developer & Kreator Digital
Dapatkan teman coding, sharing project, networking dengan expert, dan update teknologi terbaru.
Selamat! Anda telah sukses mendaftar di newsletter.