PYTHON Tutorial



COMMENTS IN PYTHON


💬 Comments in Python

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.

🔸 Single-line Comments

Use the hash symbol # to write a single-line comment:

# This is a single-line comment
print("Hello, Python!")  # This prints a message
  

🔸 Multi-line Comments (Docstrings)

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 in Functions

Docstrings are also used as documentation for functions, classes, or modules:

def greet():
    """This function prints a greeting."""
    print("Hello from Technorank!")
  
💡 Tip: Use comments wisely to describe complex code or logic. Avoid obvious comments that repeat the code.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review