How to Write Comments in Python | Python Tutorial for Beginners

preview_player
Показать описание
In this quick video, we'll learn how to write Python comments.

0:00 What is a comment?
0:04 What are comments used for?
0:14 How to write a comment in Python
0:26 What is an inline comment?
0:38 Using comments to disable code
0:57 Best practices for writing comments

A comment is a line of code that is ignored by the interpreter. It is often used to add some documentation that explains the code , to make some suggestions for future changes, and to identify problems that need to be addressed. In Python, simply start the line with a hash character in order to create a comment. You can add more comments as you see fit, and place them anywhere in your code. You can even add them in the same line that has code that you'd like to be executed. These are called inline comments.

And when we run this program, we see that all the comments are ignored.

Comments are often used to disable lines of code as well. This can be pretty useful if you want to prevent lines from being executed without having to delete the code. Perhaps maybe you're testing some things out and you're not quite sure yet whether you want to remove the lines or not.

When writing comments, it's a good practice to keep them brief and concise. And remove comments that don't really add any value, like these ones for example. These variables are already self-explanatory because of their descriptive names, so we don't need these comments to describe them any further.

And that is it for this video on how to write comments in Python. Thanks for watching!

If you like the content, please like, comment, and subscribe.

#PythonForBeginners #LearnToCode #PythonTutorials
Рекомендации по теме
visit shbcf.ru