4. Getting Started with Python
Higher Secondary · Computer Science · Science Stream

Getting Started with Python

A first look at Python — why it's translated the way it is, what makes it such a popular high-level language, and how to actually write and run a program using the IDLE IDE in interactive and script mode.

4.2(a) · Live Tool

Try the IDLE Shell (Interactive Mode)

In interactive mode, you type a statement at the >>> prompt and press Enter to see the result immediately. Try print("Hello World!!") or an arithmetic expression like (12+5)/2 below.

IDLE Shell 3.10.12

● live
Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
Supports print("text"), print(expr), string concatenation with +, and direct arithmetic typed at the prompt — just like a calculator.
4 · Intro

From Source Code to Bytecode

A program is a collection of instructions a computer executes to perform a task, written in a programming language. Since a computer only understands machine language, a translator — a compiler or an interpreter — converts high-level code (C, C++, Java, Python) into a form the machine can run.

How Python Translates

Python uses an interpreter, which translates and executes code line by line. When a program runs, the source code is first converted into bytecode — a low-level set of instructions the interpreter understands.

Why Bytecode Matters

Bytecode is not machine code and cannot run directly on hardware, but it is platform independent — the same bytecode runs on different systems, and it helps programs execute faster by avoiding repeated compilation.

Did You Know? — Guido van Rossum
Python was developed by Guido van Rossum, a Dutch computer programmer, who began working on it in the late 1980s. The first official version, Python 0.9.0, was released in 1991. He named it after the British comedy group Monty Python's Flying Circus — he was a fan of the show and felt "Python" was short, memorable, and a bit quirky, matching the language's goal of being simple and accessible.
4.1

Introduction to Python

Python is one of the most popular programming languages, renowned for its simplicity, extensive features, and strong library support. Its simple syntax lets beginners focus on programming logic rather than complex code structure — Python code reads almost like plain English.

Libraries

Reusable collections of functions, classes, and modules for specific tasks — mathematical data handling, graphics, or networking.

Frameworks

Provide a complete structure for building applications. Django and Flask power web development; Pandas, TensorFlow, and Scikit-learn support AI, machine learning, and data science.

Cross-Platform

Python code runs on Windows, Mac, and Linux without significant modification.

Open Source

Its source code is freely available to use, modify, and distribute — cost-free, flexible, and continuously improved by a large global community.

Fewer Lines of Code

For a given problem, Python normally needs fewer lines than languages like C++ or Java — a preferred choice for many developers.

Widely Used

As a high-level language, Python is versatile — used in web development, data science, automation, artificial intelligence and many more domains.

4.2

Python IDEs

An Integrated Development Environment (IDE) is a software application that provides a comprehensive platform for writing, debugging, and testing code. You may use any suitable IDE, but a Python interpreter must be installed on your computer to run your program.

Steps to open IDLE (version 3.10.12, on GNU Linux 22.04.5 LTS): 1. Press the Super key to launch the desktop search bar 2. Type 'idle' in the search bar (upper or lower case) 3. Click the IDLE icon to open the IDLE Shell The symbol >>> is the Python prompt — it shows the interpreter is ready to execute instructions.

Why Use an IDE?

IDEs enhance productivity, simplify development, and improve code quality — making them essential tools for programmers, whether writing a single line or a full script.

The IDLE Shell

Opening IDLE launches the IDLE Shell, which lets you write instructions that are executed directly by the Python interpreter.

4.2(a) – 4.2(b) · Live Tool

Two Modes of the Python Interpreter

Instructions can be run in interactive mode, one statement at a time, or written and saved as a script for repeated use. Flip between the two below.

Interactive Mode vs Script Mode

● live
—

—

Interactive mode is convenient for quick testing but can't save code for later; script mode fixes that limitation by letting you save, edit, and re-run a whole file.

Interactive Mode

How It Works

A Python statement is typed directly at the >>> prompt and executed by pressing Enter — the interpreter shows the result immediately, and the prompt reappears for the next command.

Shell as a Calculator

The IDLE shell can perform arithmetic operations — addition, subtraction, multiplication, division — directly at the prompt, showing the result on the next line.

>>> print("Hello World!!") Hello World!! >>> print(5+2) 7 >>> (12+5)/2 8.5

Limitation: code typed in interactive mode cannot be saved — to run the same code again, it must be retyped. Script mode overcomes this.

Script Mode

Writing a Script

A Python program is written in a file using File → New File (or Ctrl+N), which can contain more than one instruction. Save it with the .py extension — by default, in the current working directory.

Running a Script

Execute the saved file using Run → Run Module, or the shortcut key F5. The Python Shell then displays the output of every instruction in the file, one after another.

test.py
print("Hello World!!") print(5+2) print((12+5/2))
Shell Output
========== RESTART: /home/kite/test.py ========== Hello World!! 7 14.5
Let Us Do

Quick Recap

Tap a question to reveal the answer or a worked hint.

What happens when you run print("Hello” + "World") in Python?

Python concatenates the two strings and displays HelloWorld — with no space in between, since the + operator here joins text directly rather than adding numbers.

Compare the + operator in print(25 + 12) and print("Hello" + "World").

Between numbers, + performs arithmetic addition (25 + 12 gives 37). Between strings, + performs concatenation — it joins the two pieces of text together rather than adding them numerically.

Why is Python's bytecode described as "platform independent"?

Because the same bytecode produced from a Python program can run on different operating systems and hardware, as long as a compatible Python interpreter is available to execute it.

What is the main limitation of interactive mode, and how does script mode solve it?

Interactive mode cannot save code — it must be retyped to run again. Script mode solves this by letting you write multiple instructions in a file, save it with a .py extension, and re-run or edit it whenever needed.

How would you find the area of a circle with diameter 12 cm in Python?

Take the radius as diameter ÷ 2 (6 cm), then compute area = π × radius². As a Python instruction: print(3.14 * (12/2)**2), which prints the area.

What key do you press to run a saved script in IDLE, and what menu sequence does the same job?

The function key F5 runs the module. The equivalent menu sequence is Run → Run Module.