Table of Contents
This post will show you how to run the storical “Hello World” program in Python.
For the uninitiated, the Hello World program has the purpose of printing the “Hello World” string on the screen.
Usually this program is the first step in learning a new programming language.
I leave you this interesting article for those wishing to deepen the history of the hello world program.
Write the Hello World program in Python
The only prerequisite is to have a Python version installed on your computer.
If you have read this post on how to create a virtualenv fine, but for this program we won’t need it.
Let’s start creating a new file called, for example,
If you change the name, just be sure to use the correct one for the next tutorial steps.
Once the file has been created, the next step is to write the program!
The final step is to copy and paste the code above in your file and save it.
As you can see, the program it is very easy indeed there is just one line of code.
Before seeing the program output, let’s focus on the python function called
print(*objects, sep=’ ‘, end=’\n’, file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end, file, and flush, if present, must be given as keyword arguments.
The one above is the definition present in the Python documentation but, in simple words, we can say that the
If you got here the only thing you are missing is running the program.
Open a terminal and type the following command:
If everything worked correctly the output should be this:
A common error is
can't open file 'hello_world.py': [Errno 2] No such file or directory
This means that you are in the wrong directory, or more simply that the
hello_world.py file is not in the directory where the terminal is located. To fix it, just move in the correct directory and lunch again the command.
Following this simple tutorial you have learned how to create and run the Hello World program in Python.
Now you are ready to delve into the other basics of the Python programming language.
Let me know in the comments if this post was helpful to you and if you ran into any issues!