INTER­FACE



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!

Change the theme just the way you like it. The main rule is that it must be comfortable and pleasant! Configure Python not to work, but to create!


THE SHELL INTER­PRETER


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.

The basic objective of the interpreter is to translate programming language that we understand into machine language that no one understands except for the processor.

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! >>>



FIRST COM­MAND


We have already used one of the Python commands - print(). Let's take a close look. It consists of two parts:

The command (it's also called a function or a method) print() allows to display arguments that you put in the brackets on the screen. If you use a string as an argument, be sure you put the text in quotation marks. If we speak about numbers, simple usage of brackets is enough. When you need to use several arguments, put a comma between them.

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, security code of your card. Try to get the current year at the output, typing it without quotation marks in the brackets.

Examples

print("Wall Street") print("Viktor") print(2020)

We will print really, really much information with print().

Python Shell is the interpreter of the Python language. It can accomplish only one command at a time. For example, when we type the command print() and press Enter, Shell executes it at once.

To write and to save a multi-line program with the Shell is impossible. So what are we supposed to do?


FIRST PROGRAM


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?

  1. Save the program. Get used to the hotkey "Ctrl+S" not to press again File and Save, it is a very, very boring way of programming.
  2. Launch the program. Launching means sending a message to the interpreter to accomplish all the string of our code sequentially. Pay attention to the word sequentially. The interpreter will read our file from top to bottom, from one line to another. When the first line is executed, the second one will start running. After the second comes the third and so on, until the whole file is executed.

    To launch the program, click on Run - Run Module or just (remember it!) press the F5 key.

Come to see the result:

Hi! 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.


SUMMARY


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.

Do an experiment. Launch the file of your program with .py extension right in Windows by double-click on the shortcut. The black window of console will flash before your eyes, and probably you will see God the result of the work of the print() command.

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-2021 Viktor Trofimov
© 2019-2021 Translation and adaptation by Danil Shentsov
[ Top page ]