Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

There are two big reasons why you should learn Python.

First, Python is a very simple language


with a straight forward syntax, which makes it a particularly good language for beginners.
Second, and, I would argue the most important, Python has become an extremely popular
language. According to techworm.com, Python is the fourth most popular, and, the most widely
used high-level programming language. It is great general purpose language. This means there
are plenty of jobs to be had. Who cares if you are great at Brainf*ck, or, LOLCODE, if there are
no jobs. And, yes, those are real programming languages.

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:

1. Python 3.6 or later version.


2. IDLE3 to write the program.

First, let’s check to see if python is installed on your machine.

On Linux open a command prompt and run the text in Listing 1:

clete@thevortex:~$ python3 --version


Python 3.6.5
Listing 1

As long as your version is at least Python 3.6 you should be good to go.

Installing Python 3.6, and, IDLE 3

If you have to install Python on Linux, open a command prompt and enter the following text
displayed in Listing 2:

clete@thevortex:~$ sudo apt-get install python3.6


Listing 2
If you have to install IDLE on Linux open a command prompt and enter the following text
displayed in Listing 3:

clete@thevortex:~$ sudo apt-get install idle3


Listing 3

Now, I will create a simple “Hello World” program in Python 3.6 just to make sure that your
system is setup correctly.

Writing your first Python program.

Once Python and Idle are installed we can start to write the Hello World program open IDLE 3.

On Linux enter the following text in your console displayed in Listing 4:

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.

Python 3.6.5 (default, Apr 1 2018, 05:46:30)


[GCC 7.3.0] on linux
Type "copyright", "credits" or "license()" for more information.
>>>
Listing 5 is displaying text in IDLE in Linux.

Listing 6 displays the menu items displayed in IDLE are as follows.


File Edit Format Run Options Windows Help
Listing 6

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”.

Python 3.6.7 (default, Oct 21 2018, 08:08:16)


[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========= RESTART: /home/clete/Public/python/Article1/HelloWorld.py =========
Hello, World!
>>>
Listing 8

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.

Ahead, warp zillion!

You might also like