评论#
介绍#
Python 中的注释用于在代码中添加解释或说明。它们不会影响代码的运行,并且有助于阐明逻辑、记录功能或暂时禁用部分代码。
Comments#
单行注释以 #
(读作“井号”)开头,一直持续到行尾。
def main():
# This is a single-line comment
console.print("Hello!") # Print a greeting message
# Start threads — Do not delete
start_thread(main)
def main():
# Print a greeting and then a farewell
console.print("Hello!")
console.new_line()
console.print("Goodbye!")
# Start threads — Do not delete
start_thread(main)
Multiline String Comments#
三引号字符串注释(“”” “””
或 ‘’’ ‘’’
)可用于多行解释。虽然从技术上讲它们是字符串对象,但如果未赋值给变量,它们也可以用作注释。
def main():
"""
This project prints a greeting message,
followed by a farewell message
"""
console.print("Hello!")
console.new_line()
console.print("Goodbye!")
# Start threads — Do not delete
start_thread(main)