Comments are lines in the code that are ignored by the Python interpreter. They are used to explain the code and make it more readable.
Use the hash symbol # to write a single-line comment:
# This is a single-line comment
print("Hello, Python!") # This prints a message
Although Python doesn't have a specific multi-line comment syntax, you can use triple quotes ''' ''' or """ """ as a workaround:
'''
This is a multi-line comment.
Used to explain something in detail.
'''
print("Learning Python")
Docstrings are also used as documentation for functions, classes, or modules:
def greet():
"""This function prints a greeting."""
print("Hello from Technorank!")
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!