PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Python · Theory

Python Comments

← All stacks

Theory

12/268

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.

Exam tip

Comment vs docstring in one sentence each.

Example

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

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

Short notes

  • Def# notes. Python skips them.
  • RuleDocstring under def/class.
  • RememberExplain why, not every line.

Questions

1

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

2

What does the example print, and why?

3

What mistake do freshers make with Comments?

Previous← Python OperatorsNextPython Variables →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.