Not every statement in a Python script needs to be actual executable code. Sometimes, you just want a sentence or two to explain what's going on. Such statements are called comments.
In python, anything on a line after a #
is considered a comment. It is normal
(and even encouraged) to add comments to your code to explain what's going on.
You'd be surprised how alien your own code will look like to you in a few
months.
See the following code block for an example of comments in action:
In the code segment above, the # Place a block ...
statement is ignored by
Python. It's intended for human consumption.
Look at the code in the source pane below. Before hitting the Run button, try to guess the outcome.
As you might have deduced, the second block placement didn't do anything since
it was preceded by a #
. That second line is said to have been "commented out".
© 2024 Abhin Chhabra | Sitemap