Mastering The First Spell: “Hello World” (Installing Python, Understanding Code Editors & Writing Your First Program)
Machine Language, Decimals, English or French? Is the computer a confused machine?
Right there was a Primary 4 (3rd grade) student staring at the board where the words “Machine Language” were written boldly. I thought: “Why machine language? Why binary? We made computers, we made them understand binary or didn’t we? (I don’t mean you and I, were you even born yet?) Why can’t we make them understand English or French?
Don’t tell me you’re beginning to ask that question yourself. Funny we were told the computer system only understands machine language but we use our computers and don’t write commands in binary. Don’t over-think it. You weren’t lied to, you were just not given the full explanation like that Primary 4 student.
There’s a long (probably unnecessary) story to machine language but all we need to know at the moment is that the reason you don’t have to write in binary before your computer understands your input or command is because there’s sort of an interpreter between you (the user or sorcerer’s apprentice) and the computer system. The computer stores everything in machine language but we read it as whatever language we want.
Similarly, when we write instructions (or codes) for the computer to execute, we write it in a simple language (“simple” being relative) we understand then the interpreter has to step in between us and the computer to translate our instruction to machine language for the computer to understand. This implies that we don’t need to learn machine language to command the computer or build applications that uses the computer’s memory.
Understanding that, we could proceed to learn one of the languages the interpreter readily supports; Python.
Okay wait! I hope I didn’t need to define “language” right from the start. Was going to be sure no one was defining “language” as what their momma says when they use those vulgar words. That would make whomever the third most confused person on Earth right now. The second is the person who read this paragraph and didn’t get the joke. And of course, the first is Zuckerberg.
The Python Interpreter: The Cauldron or the Flame?
Now, we know every command we input in our computer has to be interpreted. We’ll be giving lots of commands to the computer soon in python language. The computer doesn’t have an in-built interpreter for python language, we’ll have to install one.
Just before we do that, wouldn’t it be necessary to recall that computers are much more than your PCs, desktops or laptops? Your smartphones and tablets are also considered computers. If you didn’t consider that, you might have to back, reread the whole thing, who knows you might learn 3 things you didn’t realize earlier (you were really going to fall for that?). In that realization, this means we should be able to install the python interpreter into our smartphones too. We might have to wait on that installation, there’s a tool or two we still have to understand.
Source-Code Editors (Code Editors)
Remember, the interpreter is just what makes the computer understand what exactly we are writing but where do we write these commands? Definitely not in “Word” (Oh no! My macbook doesn’t have Word). The environment where we write programming languages before our interpreter does it’s work is called a source-code editor. Examples of source-code editors are Notepad++, Atom, Visual Studio Code, Kite, etc.
Integrated Development Environment (IDE)
Imagine a dragon, a very big strong creature, broad strong wings that could lift tons of weight, a breath of fire, fiery eyes. Picture the dragon in your mind (If you have something like Drogon in GoT in mind, you have a point). Now the thing is that there’s nothing we’re going to do with the dragon you just imagined (trash it) and this paragraph is not in any way related to the article. Let’s get back to work.
Integrated Development Environment (or IDE) is an application that consists of a source-code editor, build automation tools, a debugger and sometimes an interpreter. It is a complete package that a programmer needs to write codes. Build automation tools that make programming easier, a debugger that helps the programmer work out errors easily and of course a code editor without which we can’t write codes in the first place.
Examples are IDLE (the lazy IDE which comes with python originally), Komodo Edit, Virtual Studio Code, Eclipse .etc.
Python 3
Right before we go on to install python, we should go down history lane to clear out some things.
Python was first released on February 20, 1991. Python reached version 1.0 in January 1994. After 6 years, on 16th October 2000, Python 2 was released. This version was supported until January 1st, 2020 when python stopped updating anything about the version. Python version 3 was released far before python 2 became unsupported though. Python 3.0 was released on December 3rd, 2008. As at the publishing of this article, the latest release of python is version 3.9 which will be supported till 5th October 2025.
The reason for the brief walk through history is to let you understand python 3 is the present and it still has a while to stay. However, note that python 2 is currently still used. Python 2 and 3 are about 90% similar. Hence if you learn python 3, you will likely have no problem understanding codes written in Python 2. Who knows, Python 4 might just be as related to Python 3 as Python 3 is related to Python 2.
It’s okay to know if we’ll be writing any code in Python, it’ll be Python 3 (I’m not a fan of the old school).
Installing Python on PCs
Remember when I mentioned IDLE being an IDE that comes with Python? (Oh no! You zoned off on me? Not cool). You can use IDLE after installing python. I won’t be telling you how to navigate IDLE anyway but we’ll work some basic stuff with it today. If you won’t be using your PC, you might want to get back to this part. I don’t wish to bore you with the details.
To install python, head over to python.org/downloads. The correct version should be indicated at the top of the webpage. Click on the version for Python 3 and the software will start downloading.
If you love it old school and want to install a different version, scroll down the page and you’ll see a listing of other versions. Click on the release version that you want. You’ll be redirected to the download page for any version you wish to use.
Scroll down towards the end of the page and you’ll see a table listing various installers for that version. The installer to use depends on two factors:
- The operating system (Windows, Mac OS, or Linux) and
- The processor (32-bit vs 64-bit) that you are using.
For instance, if you are using a 64-bit Windows computer, you will likely be using the “Windows installer (64-bit)”. Just click on the link to download it. If you download and run the wrong installer, no worries. You will get an error message and the interpreter will not install. Simply download the correct installer and you are good to go.
Oh wait! You aren’t really good to go if you don’t know where to write your codes. Search for apps and input IDLE, you notice the IDLE app with the python version in front. Double click to open. Remember I said I wasn’t going to explain how to navigate IDLE, I’m still on my words. The interface that pops up (also called the Shell) can only be used to execute codes temporarily and with limited lines. We’ll use it today to run our codes. When you write a code and you hit enter, your code runs, brings out a result.
Installing Python on Smartphones
Variation in operating systems(OS) of smartphones makes using a specific software application for writing python almost impossible. I’ll only recommend an app for iOS and I’ll explain partial navigation of the app I’ll recommend for Android.
If you’re using iOS, an apple lover or a direct descendant of Eve, you’ll love to check out Pythonista. If you’re a free-ranger, an Android user, you should try out PyDroid3.
You can get both apps from their respective stores. For other operating systems, you could comment your OS and I’ll reply with an application that can help you.
Once you’ve installed PyDroid3, open it. Right there is your text editor, hit the play icon if you want to run your code.
Hello World! There’s a sorcerer’s apprentice in town.
It’s time to write our first program in python.
Type the following code into your text editor or Shell.
print (‘Hello World’)
You should notice that the word “print” and the words “Hello World” are in different colors. This is known as Syntax Highlighting. It is a feature of text editors where texts especially source code is displayed in different colors or fonts. The words “print” and “Hello World” serve different purposes in our program, hence they are displayed using different colors.
The print()
statement as it’s name implies is used to print out data types (a topic we’ll discuss extensively in the next article).
‘Hello World’
is a data type called a string. It refers to text. Don’t get confused, it’ll like we’re printing out text. If you run the program, you’ll get:
‘Hello World’
Done! Voila! You have just successfully written your first Python program. Cool right? Don’t be sad we didn’t get to write a lot of codes today! I mean, if you made it to this point, you must have deep interest in python or a strong commendable mind.
You made it to the end of this article. What a strong mind you have, reading my boring writing for minutes. If you’re unclear with any part, text me on Twitter @BenjaminOlapade. If you think every beginner should see this, share. Peace!