0 | How To Learn To Code: Preface


You’ve decided to learn how to code. Maybe it’s the first time you’re trying, or perhaps you’ve started once or twice in the past but never made it past a few lessons.

Programming is not easy, and the ‘getting started’ hurdle is often the toughest one to overcome. This is because programming can be rather abstract. It requires a different mindset from our human way of thinking. You’ll need to learn to think like a computer. This is the most critical part when learning to code.

My approach to teaching beginners is to remember at all times that even the most straightforward coding ideas are new concepts for beginners. Therefore I want to take the learner on a journey and accompany them along every step of that journey. Beginners following an introductory book may often find that even though the text is aimed at novices, the book overlooks some steps or covers them superficially. I want to make sure that the reader of this book understands every part of the process involved in coding. Concepts are introduced at the right time—neither too early nor too late.

The focus of this book is to make sure you understand this programming mindset as you learn about the topics you’ll need to write computer code. Learning how to use the various tools is not enough. At times it’s necessary to dig a bit deeper underneath the surface to get better acquainted with the concepts. I find that some well-placed analogies can also go a long way to help you understand why things happen the way they do.

Why Python?

What matters is that you learn Programming and not a Programming Language. This distinction is a subtle but important one. Programming is the way of thinking that’s required. It’s the process of breaking down a problem into logical steps and then systemically putting them in the right order.

To write code, you need a programming language. In this book, we are using Python to introduce you to the coding concepts. But all the general coding concepts are common across all programming languages, even if the methods and tools may vary.

Benefits Of Learning To Code in Python

Unless you have a particular reason to learn some other programming language, then Python is the best language to use. Here are some reasons for this:

  • It is one of the most popular languages in use today. So you’ll be learning a very useful language.
  • It is a broad language, with applications across a wide range of uses, from science and finance to web development and many others along the way. Other languages can be more narrow in their scope and therefore only applicable within a small range of uses.
  • It is a relatively easy language to learn and use. I cannot stress enough how important this point is when learning how to code. As a beginner and intermediate learner, your main focus is on learning the fundamental coding concepts and understanding them thoroughly. A language like Python allows you to focus on these key concepts and not on the subtleties and quirks of the language itself. In Python, it is possible to explain every single line of code, even at the very early stages of learning. This is not possible with many other languages. You’ll have to accept the "write this code and you’ll understand it later" concept when learning other programming languages that are not as friendly as Python is, and this is not ideal for beginners.
  • There are excellent resources online and superb support from the Python community.

How To Use This Book To Learn To Code

If you’re new to programming, my advice is to start from the beginning and work your way through every section in order. Do not jump across chapters. This book presents the material in an order carefully planned to make your journey to learn to code as smooth and efficient as possible.

The Fundamentals

There are two parts to this book. Chapters 1 to 5 cover the fundamentals of programming. These are topics you will need whatever you want to use coding for. There is no way of escaping these topics. You’ll read about the Climbing a Tree analogy for learning how to code later on in the book—these chapters are the main tree trunk! You have to climb the main trunk before you can start to climb the smaller branches.

Chapter 1 will guide you from the very beginning. This chapter is centred around your first coding project. This project will introduce several of the key topics in programming and you’ll get a good understanding of how a computer program is built, step by step. As you go through this chapter, we’ll take a few short detours to introduce these topics.

Chapters 2 to 4 will continue to build on the fundamentals of coding, and Chapter 5 focuses on dealing with errors and bugs when coding.

Quantitative Programming

Chapters 6 to 11 form the second part of this book. They deal with the tools needed for programming for quantitative applications, such as science, finance or other data-driven fields. If you’re interested in these topics, then you’ll find these chapters interesting and essential. But if your aims to learn to code are different, then you can ignore these chapters. You can always come back to them later.

Object-Oriented Programming and More Functions

There are two chapters in Part 2 that could also have fit in the first part. These are Chapters 6 and 7 which expand on functions and introduce Object-Oriented Programming. These are not must-know topics when you’re getting started with coding. However, you’ll soon find you’ll need these as you work on more complex projects.

Both of these topics, functions and Object-Oriented Programming, are important parts of modern computer programming. You’ll need to know about Object-Oriented Programming as you move to more intermediate areas of coding.

There is also a bonus chapter: The White Room. This is the name of an analogy I use throughout this book to help explain what’s really happening inside a computer program which will help you understand how best to write computer programs too.

Working Through The Examples In The Book | Practise, Practise, Practise

All the coding concepts are presented through examples. Some are short programs, others are slightly longer projects.

This book is not a novel. The only way to read this book (or any book that teaches coding) is to write the code and experiment with it as you go along. Yes, you can copy the code and run it, but you can also go off-piste and try things out, experiment, do things your own way. This is a very important part of the learning process with programming and it’s the only way you’ll build your confidence with coding. You can try to have a go at writing the code before you read the sections of the book that will go through the code.

The more mistakes you make, the better it is!

Before You Start | Downloading Python And An IDE

If this is your first attempt to learn how to code, you’ll need to set up your computer. You’ll need to download the Python language and an editor with which to code.

Downloading And Installing Python

Getting the Python language is the easy part. Go to python.org and choose the ‘Downloads’ tab. You will see a button to download the latest version of Python for your operating system. You can download and install this on your computer. If you’re presented with any options during installation, I would recommend you choose the default options for now.

You now have Python installed on your computer. But how can you use it? This is the part where it can get confusing as there is too much choice available. There is no best option here. There are many options because it depends on preference and, in part, on what you want to use coding for.

In the same way that you need a word processor to write in English (or any other language), you will need an editor to write in Python. Some of these are very basic text editors, requiring you to run your code via the command line. If you’re new to programming, I would recommend avoiding this option.

Instead, you’re probably better off choosing a more complete editor. These editors are often called Integrated Development Environments, or IDEs for short.

Downloading And Installing PyCharm

If you’ve done your research already and have a preferred one, then go ahead and use it. You can follow my recommendation if you don’t yet have a preference and you’d rather spend your time learning how to code instead of researching IDEs: Use PyCharm Community Edition. You can download PyCharm here. Choose the free Community edition and not the Professional one. The Professional edition is not free, and you won’t need any extra features it offers for the time being. Once again, the easiest option is to go along with default options during installation.

Opening Your First Python File

Once you’ve installed PyCharm, you can create a New Project from the File menu. A project is a folder that contains all the code that belongs to the same, er, project! My advice is to have a single project while you’re learning and not create a new project for each program you write. Think of this as your ‘learning project’ if you like. Later on, you’ll know when it’s time to start a new project for something new you’ll start working on.

Once you’re in the project, Choose New… from the File menu and then choose Python File from the menu that pops up (not the option that just says File.) You may wonder why an IDE like PyCharm designed for coding in Python, as the Py- prefix in its name shows, also gives you options for other file types. The reason is the I in IDE, which stands for integrated. These editors allow you to work on all the files you’ll need in a project. For the time being, these will all be Python files, but you’ll need other file types as well in your project in the future.

Once you’ve created a new Python file — note that Python files will have the extension .py — you should have a blank screen in front of you. You’re ready to start to learn to code.

In Chapter 1, you’ll start writing your first program right away, and I’ll guide you on how to run your program and view the output once you’re ready to run your first lines of code.

Subscribe to

The Python Coding Stack

Regular articles for the intermediate Python programmer or a beginner who wants to “read ahead”

Coming Soon…

The Python Coding Place

Sign-Up For Updates

The main text of the book is complete—I’m planning some additions and exercises and I’ll make this book available in other formats soon. Blog posts are also published regularly.

Sign-up for updates and you’ll also join the Codetoday Forum where you can ask me questions as you go through this journey to learn Python coding.

Follow me on Twitter, too


© Codetoday Limited. Codetoday Limited is a company registered in England (company number 9789836). Registered office: 13 Hawley Crescent, London, NW1 8NP, United Kingdom