Comments in Python are the short and precise description of the code block. They are the notes in a programing language. Comments are a handy feature of programing languages especially when the size of our program grows and become more complicated. You can write the comments (notes) that can describe your overall approach to solve the problem. Moreover, it also helps in the readability of code. While working in a team, comments are useful as it provides an ease to the team members to understand your code and also help you to understand it and reuse it. A comment allows you to write notes in your language most preferable in English.
How to write a comment in Python?
In python
programming, everything that comes after a hash (#) symbol is considered as a
comment. (#) sign indicates the start of a comment. Let’s take the following example:
>>> #
statement to print >>> Print (“Hello
python coders!”) Output: Hello python coders! |
>>> # Print (“Hello coders!”) >>> Print (“Hello python coders!”) Output: Hello python coders! |
>>> # This is an example of a multiline comment >>> # Print (“Hello coders!”) >>> Print (“Hello python coders!”)
Output: Hello python coders!
|
>>> """ >>>This is an >>> example of .>>> multiline comment >>> """ >>> Print (“Hello python coders!”)
Output: Hello python coders!
|
String literals that are not assigned to a variable get ignored by the python interpreter. So, you can add the comments in the triple quotes (""").
What kind of comment you should write?
While writing
the comment considers the following point:
- Clarity: Your comments should be clear enough that whenever you or your teammates read that they can easily tell the working of code.
- Concise:
Your comments should
be as much concise as possible. Don’t add the story or paragraphs describing
your code.
- Meaningful:
Comments should be
meaningful to the reader.
Comments
are much essential in professional career because most software is developed
by a team and they also view your code and understand it to add their own code.
Try to add meaningful comments and it will only be done through practice so, start
practising it right away.
That’s all
about comments in python.
If you
found this article helpful share it with others. Let me know your queries and
suggestions in the comment section below. Do subscribe my site and channel as
I’m going to upload a series of articles and videos on programming in python
and I don’t want you to miss any update.
Moreover,
you can also contact me and share your queries on Instagram, Facebook or
Twitter. I would love to provide a solution to your issues.
Stay tuned
and strive to learn. Keep learning, keep growing!
0 Comments