評論#

介紹#

Python 中的註解用於在程式碼中新增解釋或說明。它們不會影響程式碼的運作方式,並有助於闡明邏輯、記錄功能或暫時停用部分程式碼。

Comments#

單行註解以 # 開頭,一直持續到行尾。註解可以單獨出現在一行,也可以與實際程式碼出現在同一行。後者稱為「行內註解」。

# This is a single-line comment
controller.screen.print("Hello!")  # Print a greeting message

# Print a greeting and then a farewell
# in the Console
controller.screen.print("Hello!")
controller.screen.print("Goodbye!")

Multiline String Comments#

可以使用三引號括起來的字串註解(“”” “”” 或 ‘’’ ‘’’)進行多行解釋。雖然它們本質上是字串對象,但如果未賦值給變量,則可以作為註釋使用。

"""
This project prints a greeting message,
followed by a farewell message in the
Console.
"""
controller.screen.print("Hello!")
controller.screen.print("Goodbye!")