python 注釋含注釋
Python注釋 (Python comments)
Comments in Python are used to improve the readability of the code. It is useful information given by the programmer in source code for a better understanding of code and logic that they have used to solve the given problem to the reader. Comments are not executed during the compilation and also not show on the output.
Python中的注釋用于提高代碼的可讀性。 程序員在源代碼中提供的有用信息有助于更好地理解他們用來解決給讀者的問題的代碼和邏輯。 注釋不會在編譯期間執行,也不會顯示在輸出中。
In Python, comments are done by using the hash (#) and delimiters ("" or ''') symbol with no whitespace between starting. Now we will try to learn the types of comments with some examples.
在Python中, 注釋是通過使用井號( # )和定界符( “”或''' )符號完成的,開始之間沒有空格。 現在,我們將嘗試通過一些示例來學習評論的類型 。
Python中的注釋類型 (Types of comments in Python)
There are two types of comments in Python,
Python有兩種類型的注釋 ,
Single line comment (#)
單行注釋(#)
Multi-line string as comment (''')
多行字符串作為注釋(''')
1)單行注釋 (1) Single line comments)
In Python, single-line comments are used for comments one-line statements like explanations of different variables, functions, expressions, etc. To do single-line comments a hash (#) symbol is used with no whitespace when the comments go to the next line then must put one another hashtag(#) at the start of the next line. Let's see an example and try to understand how we apply the single-line comments in the program.
在Python中, 單行注釋用于注釋單行語句,例如對不同變量,函數,表達式等的解釋。要進行單行注釋,當注釋轉到末尾時,將使用無空格的井號( # )符號下一行然后必須在下一行的開頭放置另一個hashtag(#)。 讓我們看一個示例,嘗試了解我們如何在程序中應用單行注釋。
Example:
例:
# Single line comments example
# a program to print a given string and addition.
print('Welcome @ IncludeHelp')
a=2
b=5
print(a+b)
# addition of both numbers by using plus(+) sign.
Output
輸出量
Welcome @ IncludeHelp
7
2)多行字符串注釋 (2) Multi-line string comments)
As we have seen in the above example that single-line comments, for multi-line we have to put a hash (#) symbol in each line. In Python, To overcome this problem multi-line string comments using delimiter (''') are provided. It is useful when does not fit in one line. For multiline string comments, we have to enclose the string with delimiter at both ends.
正如我們在上面的示例中看到的那樣,對于多行 , 單行注釋必須在每行中添加一個井號( # )。 在Python中,為了解決此問題,提供了使用定界符( ''' )的多行字符串注釋。 當不能排成一行時很有用。 對于多行字符串注釋,我們必須在兩端用定界符將其括起來。
Note: A delimiter is a sequence of one or more characters.
注意:分隔符是一個或多個字符的序列。
Example:
例:
'''
Here we will check a given number n is even or odd
with multi-line comments in Python.
'''
n=6768
if n%2==0:
print("Even number.")
else:
print("Odd number.")
Output
輸出量
Even number.
翻譯自: https://www.includehelp.com/python/comments.aspx
python 注釋含注釋