In this article Structure of a Python Program we give the information about how to write course code in python programming step by step.

Structure of a Python Program:

A Python program is usually organized into the following parts:

Comments and Documentation

  • Single-line comments: # This is a comment
  • Multi-line comments (docstring):

“””

This is a sample Python program

Author: Santosh

“””

An Import Statements

  • Used to include libraries or modules.

import math

from datetime import date

Global Variables / Constants

PI = 3.14

Class & Function Definitions

def add(a, b):

return a + b

A simple Python program:

# This program adds two numbers

def add(x, y):

return x + y

a = 5

b = 3

result = add(a, b)

print(“Sum:”, result)

Identifiers in Python

  • Identifiers are names given to variables, functions, classes, etc.
  • Rules for identifiers:
    • Can contain letters (A–Z, a–z), digits (0–9), and underscore (_).
    • Cannot start with a digit.
    • Cannot use Python keywords.
    • Case-sensitive (Var and var are different).
    • No special characters allowed (@, $, % not allowed).

Examples of valid identifiers:

student_name

_rollNumber

totalMarks123

Invalid identifiers:

123name     # starts with digit

student-name # hyphen not allowed

for         # keyword

Keywords in Python

  • Keywords are reserved words with predefined meaning in Python.
  • Cannot be used as identifiers.
  • Python (version 3.11+) has 35 keywords.

List of Python Keywords:

False, None, True,

and, as, assert,

break, class, continue,

def, del, elif, else, except,

finally, for, from, global,

if, import, in, is, lambda,

nonlocal, not, or, pass, raise,

return, try, while, with, yield,

match, case

Example usage:

if True:

for i in range(5):

print(i)

else:

pass

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Leave a Reply

Your email address will not be published. Required fields are marked *