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 Syntax

← All stacks

Theory

8/268

Python Syntax

Syntax is the rulebook. If you break it, Python refuses to run. Indentation defines blocks — usually 4 spaces. if, for, def, class lines end with a colon, then the body sits under them. No semicolon needed at the end of a normal line.

Python is case sensitive: Name and name are different. Mix tabs and spaces and you get IndentationError. # starts a comment. Freshers coming from Java keep adding braces; Python does not want them for blocks.

Exam line — indentation is not style. It is syntax. Say that, then show one if with a colon and two indented prints.

Python Syntax — output — Adult. The print sits inside if because it is indented.

Diagram
if marks >= 40:
      print("Pass")   ← indent = block
  else:
      print("Fail")
Exam tip

IndentationError — explain why it is syntax.

Example

# Syntax
age = 18
if age >= 18:
    print("Adult")
# print("Adult")  # wrong indent would crash

Python Syntax — output: Adult. The print sits inside if because it is indented.

Short notes

  • DefIndentation defines blocks.
  • RuleColon then indent.
  • RememberCase sensitive.
  • TrapTabs mixed with spaces.

Questions

1

Explain Syntax 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 Syntax?

Previous← How to Install PythonNextPython Keywords →
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.