What is Computer

Module: M3-R5: Python Programming

Chapter: Ch1 Computer Intro

📘 What is Documentation in Programming?

Documentation is the written explanation or guide that describes what your program does, how it works, and how to use it. It helps others (and even you in the future) understand the code quickly without needing to go through each line.

In Python, documentation can include comments, docstrings, README files, and API documentation. Good documentation saves time, improves collaboration, and makes the code maintainable.

🧩 Types of Documentation
  • 1. Inline Comments: Short explanations written inside code lines to describe what that part does.
  • 2. Docstrings: Multi-line documentation inside functions, classes, or modules explaining their purpose and usage.
  • 3. Project Documentation: Includes README files or user manuals describing installation, setup, and usage.
  • 4. API Documentation: Explains how to use functions, methods, or libraries from the code as an interface.
💬 Example: Inline Comments in Python
# This program adds two numbers
num1 = 10  # first number
num2 = 20  # second number
sum = num1 + num2  # calculating the sum
print("Sum =", sum)

Inline comments (starting with #) explain each step in the program. These help anyone reading the code to quickly understand what’s happening.

📄 Example: Docstrings in Python
def greet(name):
    """This function greets the person passed as a parameter."""
    print("Hello, " + name + "!")

greet("Sourav")

Docstrings are written using triple quotes (""" ... """) and are used to describe the function, class, or module. You can access them using Python’s built-in help() function.

🔍 Example: Accessing Docstrings
help(greet)

Output:

Help on function greet in module __main__:
greet(name)
    This function greets the person passed as a parameter.
🛠️ Best Practices for Writing Documentation
  • Use clear and simple language.
  • Keep documentation up to date with code changes.
  • Use consistent formatting and structure.
  • Include examples wherever possible.
  • Write docstrings for all major functions, classes, and modules.
📚 Example: README File Content
# Student Management System
A simple Python project to manage student records.

## Features
- Add, update, and delete student records
- Search by name or ID
- Display all student data

## Requirements
- Python 3.x
- SQLite3

## Run
python main.py

This type of documentation is usually stored in a file named README.md in your project folder. It helps new users understand what the project is and how to use it.

Quick Links