Python implements an alternative approach to multi line annotations

  • 2020-04-02 13:57:53
  • OfStack

Python program comments feel very unsociable, and for those used to using /**/ multi-line comments, it's a pain to go to Python and use a single line comment using a # sign.


# Here is a single line comment
# a = 50
# b = 10
# c = 10

In fact, we can use the format defined by multi-line text to achieve multi-line comments:

"""
    # Here's a multi-line comment
    a = 50
    b = 10
    c = 10
"""

This method feels good and is no different from /**/ multi-line comments, which are useful for debugging code and can be used to comment out parts of the code with multi-line text definitions. Perhaps Python's multi-line text definition could have served as an annotation, but the manual doesn't explicitly say that it is for multi-line annotations.


Related articles: