Python – First Program

In computing, a Hello World program is one that prints the text “Hello, World!” on a display device, in most cases a monitor screen. This program is usually used as an introduction to the study of a programming language, being a typical first exercise, and it is considered fundamental from the didactic point of view.

The Hello World is characterized by its simplicity, especially when it runs in a command-line interface. In graphical interfaces the creation of this program requires more steps.

The Hello World program can also be useful as a setup test to ensure that the compiler, development environment, and runtime environment are installed correctly and working.

Hello World! 

Hello World! in various versions of Python:

Python 2.x:

print  "Hello World"

Python 3.x:

print ( "Hello World" );

Execution 

Depending on the operating system you are using, you must perform different procedures for each platform when you want to write and run a Python program. Here is a basic procedure for the main platforms:

Run a program on Windows 

Create a directory called proyectosthe drive C:\and within this, create a plain text file with the following name holamundo.pyand enter the syntax of Python 2 or Python 3 respectively.

Then run from the console MS-DOSthe following command:

C: \ Python27 \ python C: \ projects \ helloworld.py

You can see the Hello World line .

Congratulations, you have developed your first Python program.

Run a program on Mac OSX 

  1. Click Archivoand then the new Window of the Finder.
  2. Click on Documentos.
  3. Click Archivoand then .Nueva carpeta
  4. Call the folder proyectos.
  5. You are going to store all your class related programs there.
  6. Click Aplicacionesand then TextEdit.
  7. Click TextEditon the menu bar and select Preferencias.
  8. Please select .Texto plano
  9. In the empty TextEditwindow type in the following program, as you write the syntax of Python 2 or Python 3 respectively.
  10. From the menu file in TextEdit.
  11. Click on .Guardar como
  12. In the Save as: field, type holamundo.py.
  13. Select Documentosand the file folder proyectos.
  14. Click on Guardar.

How Your First Program Works

  1. Select Aplicacionesthen .Utilidades y Terminal
  2. In the window Terminalrun lsand press the key Enter. A list of all top-level folders should be given. You should see the folder Documentos.
  3. Run and press .cd DocumentosEnter
  4. Run lsand press Enterand you should see the folder proyectos.
  5. Run and press .cd proyectosEnter
  6. Run lsand press Enterand you should see the file holamundo.py.
  7. To run the program, type the following command and press .python holamundo.pyEnter
  8. You can watch the Hello World line .

Congratulations, you have developed your first Python program.

Run a program on Linux 

Create a directory called proyectoson homeits user and within this, create a plain text file with the following name holamundo.pyand type the syntax of Python 2 or Python 3 respectively.

Then run the following command from the command console:

python $ HOME / projects / helloworld.py