Software Testing Fundamentals - Annotations for Python

1. What are annotations?

Notes are texts that introduce and comment on the vocabulary, content, background, and quotations of a book or article.

We can understand it here as an introduction to a piece of code or a line of code.

 

2. Classification of annotations in Python:

  • single line comment

  • multi-line comment

  • 3. The writing of comments:

    • Single line comment:

      Starting with #, everything on the right of # is used as a description, not the actual program to be executed, which acts as an auxiliary description

      E.g:

      #I am a comment, you can write some function descriptions in it 
      print ( ' hello world ' )

      multi-line comment

      Start with ''', end with ''', and the contents of the comments are wrapped in the middle. Or start with """ and end with """.

      Multi-line comments can have newlines and blank lines, as long as they are within the scope of the ''' package, they are all comment areas.

      E.g:

      '''
          I am a multi-line comment, I can write many, many lines of function descriptions here
      
          Let's complete the following function to print a poem
          Name is: Spring River Flower Moon Night
      ' 
      ' ' print ( ' ╔═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤═╤'═╤ _
       ( ' ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ ' )
       print ( ' ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ ' )
       print ( ' ║ │Spring│Yan│Jiang│Empty│Jiang│Jiang│People│No│White│Who│Can│Jade│This│Hong│Yesterday│Jiang│Oblique│No│ ║ ' )
       print ( ' ║ │ River│Yan│Flow│Li│Sky│Band│Life│Knowing│Cloud│Home│Pity│House│Time│Geese│Night│Water│Moon│Knowing│ ║ ' )
       print ( ' ║ │Tide│with│Wan│ Flow│One│He│Generation│Jiang│One│Today│Building│Curtain│Phase│Long│Xian│Flow│Shen│Multiply│ ║ ' )
       print ( '║ │Water│Wave│Turn│Frost│Color│People│Generation│Month│Picture│Night│Up│Middle│Looking│Flying│Tan│Spring│Shen│Moon│ ║ ' )
       print ( ' ║ │Continuous│Thousand│ Around│No│No│Beginning│No│Waiting│Go│Flat│Month│Roll│No│Light│Dream│Go│Hidden│Several│ ║ ' )
       print ( ' ║Spring│Sea│Wan│Fang│Sense│Fiber │See│Poor│He│You│Boat│Wander│No│Appearance│No│Falling│Desire│Sea│People│ ║ ' )
       print ( ' ║jiang│flat│li│dian│flying│dust│month│already│ person│you│child│lingering│going│smell│degree│flower│ending│fog│returning│ ║ ' )
       print ( ' ║ flower│, │, │, │, │, │, │, │, │, │, │, │, │, │, │, │, │, │, │ ║ ' )
       print ( ' ║month│sea│he│month│ting│jiao│jiang│jiang│but│green│he│should│pound│ Wish│fish│can│jiang│ji│falling│ ║ ' )
       print ( ' ║night│up│location│photo│up│bright│month│month│seeing│feng│location│photo│clothing│chasing│long│pity │tan│stone│month│ ║ ' )
      print ( ' ║ │Ming│Spring│Flower│White│Empty│He│Year│Long│Pu│Phase│Leave│Anvil│Month│Dark│Spring│Fall│Xiao│Shake│ ║ ' )
       print ( ' ║ │Month │Jiang│Lin│Sand│Middle│Year│Year│Jiang│Shang│Thinking│People│Shang│Hua│Yue│Half│Month│Xiang│Love│ ║ ' )
       print ( ' ║ │Total│None│All│See │ solitary │ early │ hope │ send │ not │ bright │ make up │ brush │ flow │ water │ not │ return │ no │ full │ ║ ' )
       print ( ' ║ │ tide │ month │ similar │ not │ month │ photo │ photo │Flow│Win│Month│Mirror│Also│Photo│Cheng│Also│West│Limit│Jiang│ ║ ' )
       print ( ' ║ │Life│Ming│grain│See│Wheel│People│Like│Water│Sorrow│lou │Taiwan│Lai│Jun│Text│Home│Incline│Road│Tree│ ║ ' )
       print ( ' ║ │.│.│.│.│.│?│.│.│.│?│.│.│. │.│.│.│.│.│ ║ ' )
       print ( '║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║')
      print('║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║')
      print('╚═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╧═╝')
      • 4. The role of annotations:

        • Can greatly enhance the readability of the program

        • Ability to use comments for code testing

        • Can help us quickly understand the code and logic written by others

        5. Summary

        In python, there are two types of comments:

      • Single line comment:

        • only comment one line

        • Everything after the '#' sign will be commented out

        • Shortcut key: ctrl + / Shortcut key to cancel: ctrl + /

        • The content of the comment can be anything, write it at will

      • Multi-line comments:

        • Multiple lines can be commented out at the same time (single-line comments can also be implemented)

        • Multi-line comment writing: ''' comment content''' or """comment content"""

        • There is no shortcut key for multi-line comments

       

      Supplement: Chinese support in python program:

      • In the python3.x parser, Chinese is supported by default, but some additional settings are required in the python2.x parser.

      • If you need to use Chinese in the parser of python2.x, you need to write the following code at the front of each .py file:

      • # coding=utf-8
        • Otherwise, an error will be reported.

        • In addition, python officially recommends that the best writing form is:

          # -*- coding:utf-8 -*-

          Of course, both are possible. The effect is the same.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325173973&siteId=291194637