Start Coding
What is coding?
It’s no magic. It’s just sending instructions to a processor in order to handle data. Sometimes the order of the instructions is a bit (or truly) hard to figure out and this sort of puzzle solving is what we call algorithmic.
All those guys we call developers are making these insane salaries in the Valley and everywhere in the world just doing this? Well, I kind of oversimplified the job description, but at the root of it, it’s just that. Of course, there are basic programs and then we combine them and create the great apps of AI, massive search engines and all the wonders you can think of and their creators really deserve their six figures.
in this series, we will start from the ground up. I suppose that you know really nothing and for some reason, say curiosity, you just woke up and decided to start learning how to code. You have a computer, this is a pre-requisite but I am not sure I needed to mention this, and … a bit of time. Let’s go!
Is python installed on my computer?
if you use a Mac or a Linux machine, the answer is yes. If you use Windows, the answer is … probably no. To check this out, open a Terminal or a command prompt (cmd.exe) on Windows. This is the dark background text-only utility that lets you enter those weird commands as we did at the old-time of MS-DOS. If you don’t know how to do this google can help or ask me in the comments below and I will provide some more details.
Then at the prompt, please type: (the $ sign is just the prompt symbol, do not type it)
$ python --version
You should get something like Python 3.x.y with x at 5 or more. I have Python 3.8.0. If get an unknown program error or Python 2.7.something you need to install a recent version of the python program. To do so, go to https://www.python.org/downloads/ and pick the latest available version depending on your Operating System (Mac OS X, Linux or Windows). Follow the installation process and accept default settings when prompted. Now you should retry the python –version command and get a Python 3.8+ response showing. Great! Do not close the black Terminal window, we will need it again.
Hello World!
The most simple program all beginners write at day 1 is called an hello world. This was the first sentence Linus Torvalds wrote on a forum when he started his new OS, now called Linux. This is part of the geek history. So our first python program is going to display the message “Hello World!”. Ready?
Open the most basic text editor you have on your computer. SimpleText on a Mac, Notepad on Windows. Do not use a word processor like MS Word, it adds a lot of hidden things, just the dummy notepad. Then type:
print('Hello World!')
And save the file as helloworld.py on your computer in a place where you can easily navigate. If you are on a Windows PC, I suggest you create a python directory at the root of the C:\ directory, if you have rights for this. If you are on a Mac, create a folder in your Home folder.
Now move to the python folder you just created using the Terminal window and cd commands. If you are on a Windows PC, you have to type something like this:
C:\>cd C:\python
On a Mac or any Linux:
$ cd ~/python
and then …
$ python helloworld.py
It should show Hello World! and you should tick this day on your calendar as your first day as a python coder!
What if it doesn’t work?
Welcome into the world of programming. One hour of programming, ten hours of debugging! Let’s just check out.
Is your python program really working? Type the version command to make sure:
$ python --version
If you get Python 3.x answer, it’s here. If you do’nt get this answer, something went wrong when installing python, redo the process that was described just above.
Is your helloworld.py script really saved in this directory? You can double-check using the graphical tools that are File Explorer on Windows or Finder on a Mac. Or by typing the following command on Windows
C:\python\>dir
Or on a Mac
$ ls
These commands list all the files or directories that are present in the current directory. If helloworld.py is not here, go back to Notepad and save your one-liner as helloworld.py in the directory you are looking for it.
If this doesn’t work, do not hesitate to post a comment in the comment section just below.
The Python Interactive Shell
The Python Interactive Shell is an easy way to type python commands and see what they do. It is sometimes called the python REPL. To launch it, just type python from the command line. You should see something like this
$ python
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
The three > symbol is the python prompt. Now, every time I will write >>> in my examples, I will suppose you are using the python interactive shell. It is very important you use it and get familiar with it, especially with multi-line commands. But we will talk about this later.