Python Comments — Python Technical Interview Questions & Answers

Python Comments

Python Comments

  • Comments are notes for humans. Python ignores them while running. One line starts with #. Write why, not “x = 1 assigns 1”. Obvious code plus a noisy comment looks like copy-paste notes.
  • A docstring is """...""" right under def or class. help(fn) shows it. Several # lines can explain a tricky block. Don’t confuse a triple-quoted string in the middle of code with a real docstring — placement under def/class matters.
  • Python Comments — output: 72. The # lines do not print.

Technical Interview Tip: Comment vs docstring in one sentence each.

Code Examples for Python Comments

Example

# Comments
# marks out of 100
marks = 72
print(marks)  # real print

Python Comments — output: 72. The # lines do not print.

How to Explain Python Comments to an Interviewer

Explain Comments as if you are teaching a junior — definition, then one tiny script.

# notes. Python skips them. Docstring under def/class.

What does the example print, and why?

Python Comments — output: 72

What mistake do freshers make with Comments?

Explain why, not every line.