Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Comments | Basic Syntax
Introduction to Python with Cursor

bookComments

メニューを表示するにはスワイプしてください

In Python, comments are lines ignored when the code runs. They don't change the program but help explain what it does, leave notes, or disable lines during testing. Comments make code easier to read for both beginners and experienced developers.

Single-Line Comments

The most common comment in Python starts with the hash symbol #. Everything after it on the same line is ignored by Python. This is useful for explaining what a line or block of code does.

Multi-Line Comments

Python has no special syntax for multi-line comments. You usually write several single-line comments in a row, each starting with #.

Another option is to use triple quotes (''' or """). These are string literals, but if not assigned or used as docstrings, Python ignores them. Use this method carefully to avoid confusion.

What Comments Are Used For

Comments make code easier to understand, especially in large or shared projects. They are used for:

  • Explaining complex logic;
  • Documenting why decisions were made;
  • Labeling sections of code;
  • Temporarily disabling lines while testing;
  • Adding TODO notes for future improvements.

Summary

  • Comments are ignored by the Python interpreter;
  • Single-line comments begin with #;
  • Multi-line comments are simulated using repeated # or occasionally triple-quoted strings;
  • Use comments to explain, organize, and debug code.
question mark

Which symbol is used to start a single-line comment in Python?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  2

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  2
some-alt