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
● liveFrom 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.
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.
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.
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.
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
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.
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.
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.