Using IDLE
I'll be honest - in my opinion, IDLE is not the most ideal type of code editor/programming environment to program Python with, let alone be used in the software development workflow. However, it's mostly to cater as a tool for use during your practical exams, and for the purposes of this module, it will suffice. Nevertheless, let's run through how to use IDLE to start programming in Python, and perhaps one or two modifications I would make to the environment.
IDLE Shell
When you launch IDLE, the first thing that opens up is what we call a Python Shell. The shell is the a command-line interface (CLI) to your computer, similar to your machine's Terminal or Command Prompt window.

Right here, you are able to run Python commands and see results instantaneously. In fact, it is possible to treat it as a simple calculator interface. Try entering some simple arithmetic expressions into the shell:
2 + 219 + 2069 / 3 - 20(-45 / 4)**2(which means \((45\div 4)^2\))((2+0+2+5) * (2-0-2-5))^2(which means \([(2+0+2+5)\times (2-0-2-5)]^2\))
Notice that you will obtain the simplified result of the typed-in arithmetic expression. The way how this Python shell works follows the "REPL" cycle (i.e., read, execute, print, loop).
- Read the entered command/statement/code
- Execute the entered command/statement/code
- Print the obtained result from executing the command/statement/code
- Loop - repeat R.E.P. all over again with the next entered command/statement/code
Python Shell outside of IDLE
You can also access the Python shell interface outside of IDLE, either by:
- typing in
pythonorpython3in the Terminal (enterexit()orquit()to exit the interface); or.. - opening the program from the given shortcut in the Start Menu, titled "Python version here (64-bit)"
Creating and Using a Program File
Now say you require running each of the statements you typed in the same sequence as you have done, perhaps with minor tweaks to each statement. You may find that it's not efficient to work solely on the shell command line, as you would need to re-enter each statement or line manually, among several other disadvantages. Here, it is better to create a new file to contain each of your statements.
To create a new file, select File from the top menu bar, then New File. You may also do so using the key combo Ctrl+N for Windows or Cmd+N for macOS.

You should then be presented with a new blank window like as follows:

Right here, you can proceed include your statements to be executed in succession from the get-go.
Save the following file as test.py.
Now, let's run this program file.
In your program file window you just populated (i.e., test.py), select Run, then Run Module.
You can also do this by pressing F5.
You may notice that it switches you back to the IDLE shell window, but no result is printed. Why is that?
When you type out an expression or line of Python code in the IDLE shell, the result is printed immediately following the R.E.P.L. cycle.
However, when running code from a program file, the printing is not done automatically.
You will need to surround each of your expressions using the print() function.
With this amendment, the results should then be printed as soon as you try running the module (i.e., Run \(\rightarrow\) Run Module or F5).
| test.py | |
|---|---|
Switching gears from here, let's print out a message - the classic "Hello World!" example.
| test.py | |
|---|---|
And with that, you are pretty much set to start learning how to program in Python! Here are another bunch of code snippets you can try running by yourself.
| test.py | |
|---|---|
Additional Option: Line Numbers
I like having line numbers - one reason is that when I get errors, I can cross-check where the problem sources are easily when they arise. You can configure the program file window to include line numbers when they appear from the settings. You can also activate this setting manually each time from selecting Options, then Show Line Numbers.
