A comment is a note in your Python code that is ignored by Python when the program runs.
Comments are useful for explaining what your code does, making your code easier to understand, and leaving notes for yourself or other programmers.
Single line comment starts with # . And Python ignores the line beginning with #
Output:
------
Hello, world!
You can also put a comment after your code:
Output:
------
Hello, world!
The usual approach is to use # at the beginning of each line:
Output:
------
Hello, world!
Another way to write Multi-Line Comment is by using: Triple double Quotes """
Output:
------
Hello, world!
Another way to write Multi-Line Comment is by using: Triple Single Quotes '''
Output:
------
Hello, world!
Note: Python does not actually have a triple-quote comment feature. In official Python syntax, the only true comment character is the hash symbol (#).
However, developers frequently use triple quotes (""" or ''') to act as multi-line comments. Technically, a triple quote creates a multi-line string literal. If this string is not assigned to a variable, Python allocates it in memory and then immediately ignores it, allowing it to mimic a comment.