コメント#

導入#

Pythonにおけるコメントは、コード内に説明や注釈を追加するために使用されます。コメントはコードの実行には影響せず、ロジックの明確化、機能の説明、またはコードの一部を一時的に無効にするのに役立ちます。

Comments#

1行コメントは # で始まり、行末まで続きます。コメントは単独で1行に記述することも、実際のコードと同じ行に記述することもできます。後者は「インラインコメント」と呼ばれます。

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)