![]() Since there's no built-in support for multi-line comments in Python, we can use a triple-quoted multi-line string for creating block comments. If you use 4 spaces (or a tab) for indentation, you will get an indentation error. Print ("Block Comment") Output: Block Comment If we use it to comment out multiple lines of code in Python, that block of code will be ignored, and only the lines outside the docstring will run.ĭespite the fact that triple quoted string literals do not generate code, they are handled as such and must be indented properly within blocks in order to function properly! Input: """ These strings should not be confused with Docstrings (triple-quoted string literals appearing right after a function/class/module to create documentation). In order to write a proper block comment in Python, we can use triple-quoted syntax with multi-line strings. Print ("Block Comment") Output: Block Comment Using triple-quoted string literals to create block comment in Python Since only a line of code after the # character is considered a comment, so it is great for single-line comments, so you can use it as many times as you want in a single code. Any line of code starting with # in Python is treated as a comment and gets ignored by the compiler. The most common way to comment out a block of code in Python is using the # character. Using multiple single # line comments to add a block comment in Python A block comment has a start and an end sign, and the computer ignores everything in between. The first is known as a single-line comment because it only applies to a single line in the "source code"(the program) and the second type of comment is a Block comment, and it usually relates to a paragraph of text. There are usually two ways to comment in any programming language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |