

The example image below multiline commend and docstring: Many projects and organizations are using this kind of comments when they want to have good documentation. Here you can find an example for such: def complex(real=0.0, imag=0.0):

Multiline docstrings exampleĭescriptive multiline docstrings help for understanding and maintaining the code. Note 2: For one liners it is recommended the quotes to be on the same line as the comment. Note 1: Even if a docstring contains only one line, triple quotes should be used because it's easier to expand it in future. What is a docstring? The first statement in a class, method, function or module definition which is a string is called a docstring. Unless used as docstrings, they generate no code! :-)Īccording to this tip you can do comments in this way: """line1 Guido van Rossum (the Python creator, Python BDFL) tweeted once a "pro tip" for Python multiline Python tip: You can use multi-line strings as multi-line comments. This is the default comment for most popular Python IDEs like P圜harm, Sublime, VS code. Python multiline comment would look like to: # This Some languages like Java have native support for multiline comments. In Python there is a special symbol for comments which is #. How to comment out multiple lines in Python Multiline comment is created simply by placing them inside triple-quoted strings: '''/ """ and '''/ """.īoth examples have valid syntax in Python. Multiline comments in Python can start with ''' and end with '''. PEP 8 and bigger part of the community prefers to comment out like: # This is a comment One option is to add # at the start of each line. Python has several ways to comment multiple lines in Python.
