lettura simple

How to write a program in Python

In this lesson I'll explain how to develop your first program in Python language. It is very easy. To take this online lesson you need to have python installed on your PC ( see how to install python ).

Open the Python IDLE editor

If you are using a PC with the Windows operating system, click on Start at the bottom left.

Then select the IDLE application

how to open Python in Windows

The Python console appears on the screen.

Now click on File in the top left menu.

click on File in the top menu

Then select the New File to create a new program.

Select New File

The IDLE editor window opens on the screen.

It is the editor that allows you to write a program.

idle editor of Python

The difference between IDLE editor and console. The IDLE editor and the Python console are two different things. Don't get confused. The editor allows you to write, save and run a program. On the other hand, the console allows you to execute python commands directly. You cannot save a python program with the console. To save the command sequence you need to use the IDLE editor.

Now you can start programming in python.

Write the program in python

In the first line of the source code, type print("Hello World")

write a simple program to display hello world

Warning. In this lesson I use version 3 of Python. If you are using Python2 remove the brackets, type print "Hello World".

Now click on File at the top left.

Then select the Save As item and save the program on your PC.

Select File and Save as

The python program file name must have a name ending with the extension .py.

Why save the program? If you save the program on your PC, you can run or modify it whenever you want. That way you don't have to type it every time.

Now you can run the program.

Run the program in python

To run the program press on Run in the top menu.

Then select the Run Module item.

Select Run and Run Module or press F5 key

Note. To run a python program you can also press the F5 function key on your PC keyboard. It is a more direct way.

The Python interpreter opens the shell which reads and executes your program.

The message "Hello World" is displayed on the screen.

the output of program that display "hello world" on the screen

You made your first program in Python

Now try replacing the string "Hello World" with any other phrase and run the program again.

This is a very simple tutorial but it allows you to understand how to write a python program.

In the next few lessons I will explain something more difficult to you.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin