Diff between # and """

what is the difference between # and “”" in python.

# is used to create a single line comment (a comment is something that is completely ignored by the compiler):

print("Hello!")
#print("HI")

Only Hello! is printed.


"""/""" are used to create multiline strings; strings with the formatting preserved:

print("""
hello
world!
"""

Will print:

hello
world

"""/""" Can also be used to create multiline comments:

"""
This is a multiline
comment. It is
ignored by the compiler
"""
1 Like

okay :grin: Thanks for the detailed explanation. i knew that ‘’’ was used for multiline strings but got confused when it was used to used to comment in codecademy while i was learning a course but your explanation made it clear that ‘’’ can be used also as a method for commenting multiple lines and # is for only single line.

1 Like