Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Program Structure of Python

Lesson 4 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

Program Structure of a Python Program

Unlike C/Java, Python has no mandatory main function, no semicolons, and uses indentation instead of braces to define blocks.

# 1. Comments / documentation
"""
This program demonstrates the structure of a Python program.
"""

# 2. Import statements
import math

# 3. Global variable / constant
PI = 3.14159

# 4. Function definitions
def area_of_circle(radius):
    return PI * radius ** 2

# 5. Main logic / entry point
if __name__ == '__main__':
    r = 5
    print("Area:", area_of_circle(r))

Key structural rules

  • Indentation defines blocks — typically 4 spaces. Inconsistent indentation raises IndentationError.
  • No semicolons required — a newline ends a statement (semicolons are optional to put multiple statements on one line).
  • Case sensitiveValue and value are different identifiers.
  • if name == 'main': — the conventional entry point; code here runs only when the file is executed directly, not when imported as a module.
# Multiple statements on one line using semicolon (allowed but discouraged)
a = 1; b = 2; print(a + b)
# Indentation error example
if True:
print("This will raise IndentationError")   # missing indent

Comments in Python

# Single-line comment

"""
Multi-line comment /
docstring (also used for documentation)
"""

'''
Alternative multi-line
comment style with single quotes
'''