COMMENTS IN PYTHON
WHAT IS A COMMENT
COMMENTS IN PYTHON
WHAT IS A COMMENT
Comments in a programming language are textual notes that programmers include in their code to describe what the code does. These comments are ignored by the compiler or interpreter, meaning they do not affect the program’s execution. The main purpose of comments is to make the code more understandable for humans .
UTILITY OF A COMMENT
- Documentation:
Comments provide explanations about the code, making it easier to understand for others (and for yourself, when you revisit the code later).
2. Clarification:
They clarify complex sections of code, helping to break down the logic into more understandable chunks.
*3. Temporarily Disabling Code*:
Comments can be used to disable parts of the code during debugging and testing. This helps to isolate problems or test specific sections without removing code permanently.
*4. Notes*:
Programmers often use comments to leave notes for themselves or other developers, indicating areas that need further work or improvement, known as TODOs.
TYPES OF COMMENTS
- Single-line Comments :
A single-line comment in Python is a way to annotate your code with explanations or notes. These comments start with a hash symbol ( # ), and everything following the ( # ) on that line is ignored by the Python interpreter.
# THIS IS AN EXAMPLE OF A SINGLE LINE COMMENT .
print("hello world ") #it does not affect the rest of code in the line
2. Multi line Comments :
In Python, a multi-line comment allows you to write comments that span multiple lines. Python doesn’t have a dedicated syntax for multi-line comments like some other programming languages. Instead, you can use triple quotes (’’’ or ””” ) to create a multi-line string comment.
""" this i an example of multi line comment which can
be extended upto multiple line
which will be ignored by complier
"""
It is mostly used to explain the work-flow or logic behind a block of code .
TIPS TO USE COMMENTS IN PYTHON
Clarity and Relevance: Comments should be clear and directly related to the code. Avoid vague or overly verbose comments.
# calculate the area of rectangle
a= 2
b=5
area = a*b
print(area)
Update Comments Regularly: Ensure comments are updated along with the code to avoid outdated or misleading information.
Explain Why, Not What: Comments should explain the reasoning behind the code, not just describe what the code does.
Avoid Over-commenting: Too many comments can clutter the code. Use comments judiciously to enhance readability without overwhelming the reader.
CONCLUSION
Comments are one of the most essential part of programming as it enables the programmer to enhance the clarity , understanding ,readability and errorless .
Hence , using comments is a admirable practice and one should definitely use comments while working with a group .
THANKYOU
메타데이터
- post_id
- 5e7c3a02fc3a
- slug
- comments-in-python-5e7c3a02fc3a
- url
- https://medium.com/@akshat.24bca7140/comments-in-python-5e7c3a02fc3a
- canonical_url
- https://medium.com/@akshat.24bca7140/comments-in-python-5e7c3a02fc3a
- author_url
- https://medium.com/@akshat.24bca7140
- status
- ok
- fetched_at
- 2026-06-26 21:52:29