0% found this document useful (0 votes)
2 views2 pages

1.python Comments

The document explains the use of comments in Python, highlighting their role in enhancing code readability and aiding in debugging. It details the types of comments, including single-line comments, multi-line comments, and docstrings, along with best practices for writing effective comments. Key recommendations include keeping comments concise, avoiding redundancy, and adhering to PEP 8 guidelines.

Uploaded by

KARTHIKEYAN S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

1.python Comments

The document explains the use of comments in Python, highlighting their role in enhancing code readability and aiding in debugging. It details the types of comments, including single-line comments, multi-line comments, and docstrings, along with best practices for writing effective comments. Key recommendations include keeping comments concise, avoiding redundancy, and adhering to PEP 8 guidelines.

Uploaded by

KARTHIKEYAN S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link].

in

Python Comments
• Comments in Python are used to explain code and make it more readable.
• They are ignored by the Python interpreter.
• Useful for documentation and debugging purposes.
• Comments can be used to prevent execution when testing code

1. Types of Comments
a. Single-line Comments
• Begin with # and extend to the end of the line.

b. Multi-line Comments (Block Comments)


• Python does not have a specific multi-line comment syntax.
• Conventionally, multiple # symbols are used.

• Alternatively, triple quotes (''' or """) can be used, though they are
actually treated as docstrings if not assigned to a variable.

1
[Link]

c. Docstrings (Documentation Strings)


• Enclosed in triple quotes (''' or """). Used for function, class, or
module documentation.

• Docstrings can be accessed using inbuilt help()function:

Note:
We will learn more about docstrings in the Docstrings topic.

2. Best Practices for Writing Comments


• Keep comments concise and meaningful.
• Avoid redundant comments.
• Use comments to explain why rather than what.
• Follow PEP 8 guidelines for writing clean comments.
• Use docstrings for module, class, and function documentation.

You might also like