When you first start Python Shell, you'll face this white mess:
Certainly, if you get used to writing programs with the black letters on the white background, you'll feel like a fish in water. There is no accounting for tastes. Tastes differ. If you like it, leave it as it is. And so on and so on... But let me add that
you're all wrong there is a particular reason to invert colors.
Practice shows that dark-on-light text is less tiring for eyes and better holds attention of the user. Probably, that's because all pixels don't dazzle your eyes with white every second, and it doesn't strain eyes so much. You should also choose non-contrast softer colors of the text and the background. Take care of your sight. I'm super cereal!
So, select Options in the menu, further Configure IDLE:
Here choose the Consolas font, made for real programmers (for choosing another font, please, find another tutorial) and, I definitely recommend to increase the font size. Our program must be seen from far away!
Next, change the background in the Highlights tab: instead of IDLE Classic pick IDLE Dark. Come to the dark side, we have cookies!
After that, take a little more efforts as usual: click Python Comments to configure the color of the comments. If you ask me - yellow. Looks excellent.
Now (yeah!) save the theme (Python will ask you kindly for the theme's name) and confirm by clicking "ОК". That's all. What changed? The view. That's quite enough!
THE SHELL INTERPRETER
Remember this window:
It's called Python Shell (commonly just "Shell"). Shell is the window of the interpreter.
The interpreter is named like that for a good reason. Think of how the interpreter works. Do you know that the origin was written in Russian by my best friend? And this coursebook is free translation of his thought, we work a lot to present it all to you in the most appropriate way. So, I am just an interpreter from Russian to English, and my task is to explain every detail the author mentioned.
By analogy with the computer language, a program in Python is the original Russian text, a CPU is the English-speaking community, and the interpreter is a key component that translates code of the whole program in a way the CPU understands. That is, in bytecodes, in a binary command system that the processor can execute.
Try to tape in the Python Shell the following command:
print("Hi! I'm an interpreter!")
Press Enter and the command will be executed. The phrase will appear on the screen, before the prompt string, which is identified by three greater-than signs in a row >>> (they are set automatically). General view of the Python Shell will be like that:
>>> print("Hi! I'm an interpreter!")
Hi! I'm an interpreter!
We have already used one of the Python commands - print(). Let's take a close look. It consists of two parts:
What happened? After pressing the Enter key, the interpreter received the command print(), converted it into the bytecode, sent it to the CPU, and the processor "drew" the phrase we put in quotation marks at the output. Yes, it takes a lot to put ideas into practice. Get used to it.
Now, train a little. Print on the screen your name, your street, print("Wall Street")
security code of your card. Try to get the current year at the output, typing it without quotation marks in the brackets.
We will print really, really much information with print().
To write and to save a multi-line program with the Shell is impossible. So what are we supposed to do?
If we want to create an adequate program, we have to write more than one line. Sometimes, the number of lines exceeds one hundred or one thousand. Serious programs consist of tens or even hundreds of thousands of strings, great ones contain millions of strings. The work of a programmer is as interesting as complicated. Bearing in mind narrow specialization of a programmer, it looks fair that they make a great profit realizing difficult and exciting projeсts :)
As mentioned above, even two lines of code wouldn't work in Python Shell. How to fix? Right! We'll create a special file where the program will be stored.
To make it happen, you should click on File in the main menu, then New File or just press "Ctrl+N". Use hotkeys indicated next to menu items to save time, it matters:
Type the code in the window as shown in the screenshot. Replace my name by your own one:
What to do to make the program run?
Come to see the result:
This is my first program
that consists of more than one line.
Viktor, 2020 yr.
Notice that every new command print() outputs text on a separate line.
To write a program, we should launch the Python Shell at first by clicking on IDLE Python shortcut, then create a new file, and type all the code in the file.
Before running a program, you must save it on the disk. I recommend to save it right in the directory that Python offers. Usually it's the directory where Python is installed (D:\Python in my case). There is no need to create additional directories because the number of programs will grow. Choosing the file path when loading the previous program is tedious.
To run the program, use menu items or just (I really hope you would use this option) press F5.
What will happen when you press F5?
The program starts being executed. Python will write our code, convert into a bytecode, and give it to a processor in the case of successful running. The result will be seen in the Python Shell window.
If you make a typo in text (incorrect name of a command, missing or extra brackets, and so on), Python will highlight the questionable place in code when you launch a program. As an experiment, type prin() and launch or add an extra bracket print((). Learn how Python reacts in the case of a typo.
If Windows suggests you to find a right program to open the file with .py extension, perhaps, you failed with the "Add Python to Path" checkbox. Before it's too late, delete Python and reinstall it without forgetting to click the checkbox :)
Well, ladies and gentlemen, the time has come. Let's make something really serious! Checkboxes, screenshots, discussions are fun, of course, but I have prepared something more interesting...
© 2019-2023 Viktor Trofimov