Sunteți pe pagina 1din 2

Your first step into Python

Now, you have decided to learn how to program in Python, and now is the time to take the first two
important steps to get you further down the programming lane.

In this short introduction, you will learn how to use IDLE and the Python editor for writing code.

In this small tutorial, we will use Python version 2.7, but this tutorial also applies to Python version
3.3.

First open IDLE. From Windows: Start Programmes Python 2.7 IDLE (Python GUI).

In IDLE, also referred to as the Shell, you can write your code. The code is written in the line with
the 3 arrows - >>>. Try this: print Hello, world! and when you press enter, Python prints the
message 'Hello, world! In the next line. For Python 3.3 you should type this:
print (Hello, world!)

As mentioned above, IDLE is referred to as the Shell. You may also see that terms as The Console
Window or prompt is used. Never the less all terms refers to IDLE Shell.

You can write your code in IDLE and have it executed, thereby getting your results immediately.
However, IDLE the prompt is mostly used to run
small pieces of code to test intermediate results of >>> celcius = 0
distinct code. As you soon will discover, the code that >>> kelvin = 273.14
you type in each line in the prompt has to be without
errors, otherwise you have to re-type the entire code >>> celcius + kelvin
once more. 273.14
>>> celcius = 30
The prompt is widely used as an advanced calculator
because you can define your variables directly by >>> celcius + kelvin
giving these telling names. This can be illustrated 303.14
with the example to the right. Changing one of the
variables and you can directly calculate the new
result.
Using the prompt for longer parts of code is rather annoying because, if you type a mistake in the
code, you have to re-type the entire code once more to get it to work. In IDLE (the prompt) you can
open the Python editor by choosing File > New Window and this opens Pythons editor. When you
want to save your code for further use or development, you will write your code in the editor. When
you save the code, note that the default directory is in the Python 27 folder on C drive. I will
strongly recommend, that you save your code files in an other place, i.e. in Documents
My_Python_Files to keep your files separated from the installed Python files because before you
know it, you will have hundreds of different code files on your computer. Do remember to save
your code files with the extension .py (dot py)

The Python editor looks like the


picture to the right.

When you want to run a code from


a specific file, just open the file
from within IDLE. Python will
automatically open the editor
window and from here you can run
the code and get the results in the
prompt.

A little advise before ending this short tutorial. When you begin programming, use IDLE for the
first few weeks to get acquainted with this programming environment. IDLE is IDLE on what ever
computer Python has been installed on, so in situations where you do not have access to your
preferred programming editor you know how to handle IDLE.

For more on Python editors, read the python_editors.pdf from our files.

S-ar putea să vă placă și