Let’s start creating our first application in Python. A very simple application that will only display “Hello World” on the screen.
In the world of programming, “Hello World” is usually the first program written when learning a new language. It’s almost a tradition (which also has its certain charm😉).
Although it is logically very basic, the goal is to familiarize ourselves with the basic structure, run our program, and in short… make sure “everything works”.
Creating the Program
I assume you already have Python installed on your system, and a code editor like VSCode installed. Although for this first example, any text editor will work.
To create our “Hello World” program in Python, we simply have to create a text file, and save it with the .py extension.
It’s that easy. We don’t need to initialize the project, nor launch any special process. One of Python’s advantages is its simplicity. The Python interpreter will handle everything when running it.
For example, we create a folder called MyProject. You can do this with your operating system’s File Explorer, or if you do it via terminal like this:
mkdir MiProyecto cd MiProyecto
Now, inside this folder we create a text file. For example hello_world.py, although you can use any name you want.
Writing the Code
In the hello_world.py file, we will write the following code:
# Our first application in Python - "Hello World"
print("Hello World!")
This code is very simple. We simply use the print() function, which is used to display messages on the screen. In this case, we tell Python to print “Hello World!”.
Running the Program
Once we have written our code, save the file and open a terminal or command line, in the location where we saved our hello_world.py file.
Now, to run our program, we simply type the following command:
python hola_mundo.py
With this we are telling the Python interpreter to execute the hello_world.py script. For this we use the python command.
For the Python interpreter to work for you, it must have been installed to the system’s PATH.
If everything is configured correctly, we will see the message Hello World! printed on the screen.
Hello World!
That’s how easy it is! Nothing else is needed. Simply run the python command passing it the name of our script.
However, in general we will use an IDE or a code editor like Visual Studio Code, as we saw in this article How to use Python with VS Code
