我们如何在Python中创建多行注释?
When we need to comment on multiple lines/statements, there are two ways to do this, either comment each line or create multiline comments (or block comment).
當我們需要對多個行/語句進行注釋時,有兩種方法可以執行此操作,或者注釋每行或創建多行注釋 (或阻止注釋 )。
In C / C++, we use /*...*/ for the multiline comment, but in Python programming language, we have two ways to comment a section.
在C / C ++中 ,我們對多行注釋使用/*...*/ ,但是在Python編程語言中,我們有兩種方法來注釋部分。
The first way is to comment on each line,
第一種方法是在每一行上注釋,
This way can be considered as a single line comment in Python – we use the hash character (#) at the starting of each line to be commented.
這種方式可以視為Python中的單行注釋–我們在要注釋的每一行的開頭使用井號( # )。
# This is line 1 # This is line 2 # This is line 3And, the second way is to comment the section,
而且,第二種方法是評論該部分,
This way can be considered as a multiline comment in Python – we use triple single quotes (''') at the starting of the section to be commented and again triple single quotes (''') at the end of the second.
這種方式可以視為Python中的多行注釋-我們在要注釋的部分的開頭使用三重單引號( ''' ),并在第二個末尾再次使用三重單引號( ''' )。
''' This is line 1 This is line 2 This is line 3 '''創建多行注釋的Python示例 (A Python example for creating multiline comment)
''' Function name: print_text Parameters: None Return type: None Description: This function will print some text on the screen '''def print_text():print("Hello, world! How are you?")if __name__ == "__main__":# Here, we will call the print_text function# that will print some text on the screenprint_text()Output:
輸出:
Hello, world! How are you?In the above program, there are two multiline sections which we is commented,
在上面的程序中,有兩個多行部分,我們在其中進行了注釋,
Section 1: ''' Function name: print_text Parameters: None Return type: None Description: This function will print some text on the screen '''Section 2: # Here, we will call the print_text function # that will print some text on the screen翻譯自: https://www.includehelp.com/python/how-do-we-create-multiline-comments-in-python.aspx
總結
以上是生活随笔為你收集整理的我们如何在Python中创建多行注释?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java StreamTokenizer
- 下一篇: python字符串转义序列_Python