Python Hello World Program
Python Hello World Program
Alright, to avoid the angry emails I am sure to get, those languages are interesting, and, they
help to stretch your programming muscles, but I would argue, largely impractical in the typical
business setting.
In this article I will be using Linux to run the Python programs. Almost any Linux distro will do,
however, I would recommend Ubuntu or Linux Mint for beginners. If you have spent any time
writing code you should be familiar with the obligatory ‘”Hello World” program. The Hello World
program serves as a starting point for beginners, and, is used many times by seasoned
programmers to test installs of python, or, any other program for that matter.
This tutorial will gloss over you installing python 3.x and IDLE. There plenty of websites that do
a great job at going over the nitty gritty of installing this software. For instance, you can go to
https://www.python.org/downloads/ to get a good start.
Prerequisites
Needed Software:
As long as your version is at least Python 3.6 you should be good to go.
If you have to install Python on Linux, open a command prompt and enter the following text
displayed in Listing 2:
Now, I will create a simple “Hello World” program in Python 3.6 just to make sure that your
system is setup correctly.
Once Python and Idle are installed we can start to write the Hello World program open IDLE 3.
clete@thevortex:~$ idle
Listing 4
The nice part about using IDLE is it is free, and, I can almost always afford free. Yes, there are
a number of python IDE’s, but IDLE is perfect for learning Python. Additionally, whether you are
coding in Windows, MAC, or your favorite Linux distro, IDLE looks the same everywhere. If you
are thinking about purchasing an IDE with more functionality I would recommend WingWare. It
can be found at https://wingware.com/downloads/wing-101. Wing 101 is a student version you
can try for free before purchasing the pro version.
Listing 5 displays the text you should see in the IDLE application. The title of this window is
Python 3.6.x shell.
Initially we will only be using item from the File and Run menu.
Click File, and, then, New File. A window with “Untitled” will appear. Click File, and, then, Save
As. A dialog box with Save As will appear. In the File name text field enter the name of your
program. In this case, we will name it “Hello World.py”. It really does not matter what you call it
as long as you have .py as the extension.
Copy and paste the code in Listing 7 into the newly created window.
print("Hello, World!")
Listing 7 is displaying the code in its entirety for our “Hello World” program.
Click File, and, then, Save. Then, click Run and select Run Module or press F5. If you had tried
to run the program without saving, you would have seen a dialog box with the text “Source Must
Be Saved OK to Save?” If this happens just click the OK button.
If everything went according to play, the text “Hello, World!” will be displayed in the Python 3.x
Shell. Listing 8 is displaying the expected output of the “Hello World.py”.
This may seem incredibly trivial, but it tells us that the Python install went well and everything
should be working. This is good to know prior to building a more complex program.
This was just a first glance at Python. I hope you find Python as fun and easy to work with as I
do.