Help support the author by donating or purchasing a copy of the book (not available yet)



Chapter 1

Prerequisites

There are only two things you need to have done before reading this book: have Python installed on your computer. I’m not going to go through the process of doing that so I’ve left some links below on how to install it on whatever operating system you’re using. We’ll be using Python 3.7 throughout this book, however you might already have Python installed if you’re on Mac or Linux. I’ll also be developing on Windows 10 but that shouldn’t make a difference.

Secondly you should have a have a text editor installed. I recommend Sublime Text as it will provide everything we need to get started. A link to download Sublime Text is also linked below.

Python for Windows: How to setup Python on Windows 10

Python for MacOS: How to set up Python on MacOS

Python for Linux (Ubuntu): How to set up Python on Ubuntu

Sublime Text 3: Install Sublime Text 3

I also highly recommend becoming familiar with the command line. This is going to be essential if you want to be productive. I know I've said I'll be developing on Windows but I also recommend you install some linux distribution (Ubuntu is usually a good choice for beginners). You can install this along side Windows if that's what you've got installed. All great developers know the linux command line inside and out and if you work in this industry you'll be expected to know it. Below are some links on how to install Ubuntu along side Windows and an introduction to both the linux and Windows command lines.

How to install Linux along side Windows: Dual-boot ubunut and Windows

Introduction to the Windows Shell: Intro to Windows Shell

Introduction to the Linux Command Line: Into to Linux Command Line

1.1 Learning outcomes and who this book is for

Slither into Python is freely available online and aimed at anyone who wants to learn to program or wishes to learn a thing or two about computer science and has little to no knowledge about either.

No prior programming experience or computer science background is necessary. Unlike any other Python resources I have found (not that they don’t exist), they don’t explain important computer science concepts such as memory or “how computers work” which I believe is essential to becoming a good programmer (having some basic computer science knowledge can often help you get out of odd situations when programming). In this book I will cover the fundamentals of the Python programming language and also introduce these important computer science concepts and theories.

Put simply, coding or computer programming is about making computers do what you want, Computer Science is about how computers do it. Each go hand-in-hand, help you learn faster, improve your overall understanding of a language and makes you a better programmer. This book aims to do exactly that through Python.

Another really important skill all great programmers have is problem solving. Being able to think about a problem from a different perspective, break it down into an easier more manageable problem or re-frame the problem is unbelievably important.

Thinking computationally is also important (Probably most important. Most people fail because they don’t learn to think computationally). Consider making a cup of tea. It’s something we do everyday without giving it much thought. However that won’t work well for us when it comes to writing computer programs. We need to break problems down into a set of well defined steps.

Making a cup of tea:
- Boil the kettle
- Take a cup from the cupboard
- Take a teabag from the cupboard
- Put the teabag in the cup
- Pour water into the cup
- If want sugar:
    - Take sugar from cupboard
    - Put sugar into cup
- Stir the tea
- Remove the teabag
- If want milk:
    - Take milk from fridge
    - Pour milk into cup
- Stir the tea
- Remove teabag
- Drink tea

(Please don’t email me about my tea making method!).

I will also explain everything very simply in the beginning of the book and gradually become more technical as to not overwhelm you in the beginning (I found this worked really well for me when I was learning to program).

I hope that by the end of this book you will have a solid understanding of the Python programming language, a firm understanding of important computer science concepts, the ability to put problem solving techniques to good use and most importantly, think computationally.

1.2 A bit about Python

Python is an interpreted, high-level, general-purpose programming language. Now you might be wondering what all that means, so let me explain. An interpreted language is a language in which we don’t need to compile a program before we run it. Compiling is the process of translating the code we write into machine code (A language the computer can understand). With interpreted languages we essentially generate the machine code as our program runs (at run-time). This is done with the help of an interpreter. The Python interpreter is just called python .

High-level means we are abstracted away from the details of the computer. For the purposes of explanation, a low-language like Assembly is used in specialised applications such as operating systems (In fact, the Apollo 11 Guidance Computer was written in assembly and the source code can be found here: Apollo 11 Source Code). Below is a snippet of this low-level assembly language which we will re-write in Python in the following section.

SECTION .DATA
    hello:     db 'Hello world!',10
    helloLen:  equ $-hello

SECTION .TEXT
    GLOBAL _start 

_start:
    mov eax,4            
    mov ebx,1            
    mov ecx,hello        
    mov edx,helloLen     
    int 80h              

    mov eax,1            
    mov ebx,0            
    int 80h              

Python is being widely adopted by universities all around the world as the introductory language taught to first year computer science students due to its simplicity. In saying that, it may be an easy to understand language and easy to write language but it is also extremely powerful. It is used everywhere from automating everyday computing tasks to data analytics and artificial intelligence.

Python has a huge community behind it. If you get stuck on a problem or can’t make sense of an error message I can guarantee you’ll find your answer in a matter of minutes.

Python also has a ridiculous number of open source libraries, frameworks and modules available to do whatever you want to do. This makes developing your applications even more straightforward.

To top it all off, if you’re planning on making a career out of this, the average salary for a Python developer in the US is in the region of $92,000.

1.3 Our first program

In the previous section we came across some nasty assembly language code. It’s now time to write our first program. We’re going to translate that program into Python:

That’s it! It really is that simple. Create a new file in your text editor, copy the above code into it and save it as hello.py. All Python programs end with the .py extension.

Next, to run our program we need to open a terminal window. On Windows, open the file explorer and go to the directory (folder) where you saved the file. On the top of the file explorer window you will see something similar to:

This PC > Desktop > my_folder

Click into this and type “cmd” and hit enter. This will open a terminal window in that directory.

Finally, to run your program, in the terminal window next to _C:NAME>, type the following.

python hello.py

You should now see “Hello world!” was printed out. If you remember from the previous section, python is the interpreter and we’re telling it to run our program ‘hello.py’

Congratulations! You’ve written your first of many Python programs. Now I want you to forget the above program. I have it here simply to serve as a boost in motivation. In the next chapter we’ll take it right back to the very basics and get you on the road to mastering the Python language.



Help support the author by donating or purchasing a copy of the book (not available yet)



Next Chapter