What are the two types of comments in Python? How are they written?
Answer:
Answer by student
The two types of comments in Python are single-line comments and multi-line comments. Single-line comments are written by using a # symbol at the beginning of the comment . Multi-line comments are written by using triple quotes (‘’’ or “”") at the start and end of the comment.
Detailed answer by teachoo
-lock-
The two types of comments in Python are single-line comments and multi-line comments. Comments are parts of the code that are ignored by the Python interpreter and are used to explain or document the code.
- Single-line comments are written by using a # symbol at the beginning of the comment . They can be placed on a separate line or at the end of a code line. They can only span one line and cannot be continued on the next line.
- Multi-line comments are written by using triple quotes (‘’’ or “”") at the start and end of the comment. They can span multiple lines and can be placed anywhere in the code. They can also be used as docstrings to document functions, classes, or modules.
For example, if we want to write some comments in our hello.py file, we can write:
-endlock-