0% found this document useful (0 votes)
18 views10 pages

Week 8 Python Comments

The document discusses comments in Python programming, including their purpose, types, and advantages. Comments are non-executable notes inserted into code to explain and document it for readers. The main types are single-line, multi-line, and docstring comments.

Uploaded by

animemaster2k
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
18 views10 pages

Week 8 Python Comments

The document discusses comments in Python programming, including their purpose, types, and advantages. Comments are non-executable notes inserted into code to explain and document it for readers. The main types are single-line, multi-line, and docstring comments.

Uploaded by

animemaster2k
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 10

Programming –

THE ART OF WRITING INSTRUCTIONS FOR COMPUTERS

COMPUTING – YEAR 8 – CHAPTER 3


Part 3.1 – Comments
Learning objectives –
• Understand and describe the purpose of adding comments to your
program.
• Add single-line and multi-line comments to your Python codes.

Keywords –
comments, readability, interpreter, executed
Part 3.1 – Comments
What are comments in programming?
• Comments in Python is the inclusion of short descriptions along with the
code to increase its readability.
• A developer uses them to write his or her thought process while writing
the code.
• It explains the basic logic behind why a particular line of code was
written.
• Comments are just meant for the coders themselves or other developers to
understand a piece of code.
Part 3.1 – Comments
What are the uses of comments in programming?
• Comments in Python are identified with a hash symbol, #,
and extend to the end of the line.
• Hash characters in a string are not considered comments,
however.
• There are three ways to write a comment - as a separate
line, beside the corresponding statement of code, or as a
multi-line comment block.
Part 3.1 – Comments
What are the uses of comments in programming?

There are multiple uses of writing comments in Python.


• Increasing readability
• Explaining the code to others
• Understanding the code easily after a long-term
• Including resources
• Re-using the existing code
Part 3.1 – Comments
What are the advantages of using comments in python?
Comments in Python provide numerous advantages.
• Makes the code easily understandable by other programmers.
• The code becomes self-explanatory.
• Helps remember why we used a specific command, method, or
function in the code.
• Enables the interpreter to ignore some part of the code while
testing.
Part 3.1 – Comments
What are the different types of
comments in python?
• There are three types of comments: single-
line, multi-line, and docstring comments.
• The syntax of comments varies depending on
the type.
Part 3.1 – Comments
What are the different types of comments in python?
Single-Line Comments
• Single-line comments begin with the “#” character.
• Anything that is written in a single line after ‘#’ is considered as a
comment. # This is a comment
• There are two ways of using single-line comments in Python.
• You can use it before the code, above the code or next to the code.
n
Part 3.1 – Comments
What are the different types of comments in
python? Multi-line Comments
• We can write multi-line comments in two ways
• Using multiple single-line comments or using
docstring comments
• Research on how to add Python code to html or how to run Python
codes in html.
Based on your findings, write an html file and add any of your
previous Python codes.
Open your html file in the browser and check if the Python codes
run successfully in the browser.
Send your html file to me for checkup.

You might also like