Revisiting Script Mode
You have met script mode already, and you now know enough print() to write something worth saving. So let us do the whole thing properly, start to finish: open a file, write a few lines, save it with the right name, and run it — this time in IDLE, the program that came free with Python.
1First: IDLE is an IDE
When you installed Python, you also got a program called IDLE. Search for it in your Start menu and it opens. It is not just a place to type code — it is an IDE.
IDLE is the simplest one, which is exactly why we start there. There are many others, and you will hear these names:
Comes free with Python. Small, plain, and enough for everything in this course. This is the one your school will use.
Free, and what a great many working programmers use every day. More powerful, and more to learn.
Built for large Python projects. It has a tool for everything, which makes it powerful — and a lot to take in at the start.
Made for beginners, and friendlier than IDLE. It can show you your program running one step at a time.
Runs code in small blocks with the results underneath each one. You will meet it if you go on to data science.
print('Hi') behaves identically in all of them. It only changes how comfortable you are while writing it. Learn Python, not the IDE.2Writing and running a script in IDLE
Four steps, and that is the whole job. Click through them and watch what changes each time.
Type "help", "copyright", "credits" or "license()" for more information.
Step 1. IDLE opens in interactive mode — the window with the >>> prompt. You do not type your program here. Go to File → New File. An empty editor window opens.
>>> window says IDLE Shell. Shell is simply the name IDLE gives to interactive mode. Same window, same >>>, same thing you already know — do not let the extra word worry you.3The file you just wrote
Here is the whole file on its own, away from the IDLE window. This is all a Python program really is — plain lines in a saved file, run from top to bottom.
print('Ramesh Kumar')
print('Class:', 11)
print('Marks:', 87 + 8)Ramesh Kumar Class: 11 Marks: 95
Three print() calls, so three lines of output. The last one does the sum first and prints only the answer — exactly as it did at the prompt. Nothing about print() changed. Only where you typed it changed.
4Three slips that catch everyone
The >>> is Python's prompt in interactive mode. It is not part of the code. Put it in a file and you get a SyntaxError.
Save it as marks and it is a plain text file. Save it as marks.py and it is a Python program. The extension is how the computer knows.
IDLE runs the saved file, not what is on your screen. Edit a line, press F5 without saving, and IDLE will stop and ask you to save first. Say yes.
5Which mode, from here on
You now know print() and you know how to write and run a file. That is enough to write real programs, so from the next topic onwards we will mostly work in script mode. Real code gets long, needs editing, and has to survive being closed — and only a file does all three.
Interactive mode does not go away, though. It stays the fastest way to check one small thing: what does this sum come to, does this line do what I think it does. You will see it used again and again for exactly that, all through the course.
6Recap
>>>, File → Save with a name ending in .py, then Run → Run Module or F5. The output appears back in the interactive mode window, all at once.What does IDE stand for?
You save your file as 'marks' instead of 'marks.py'. What happens?
Which key runs the file you are editing in IDLE?