Introduction

Many people idly contemplate learning how to code. It seems like something that could be of use, but many are too intimidated to jump in and try. Maybe they believe it’s too late to start learning a skill like programming, or they believe they don’t have enough time. Maybe they get lost too quickly, because the book they found is written for someone with previous experience with coding. It seems like an impossible task. The goal of this book is to break down the concepts behind programming into bite-sized chunks that are easy to digest as well as immediately useful.

Learning to Program

For many people, learning to program seems like an impossible task. It’s painted as a field that requires a crazy amount of math, years of education and training, and, once you’re done with that, endless hours of constantly banging away at a keyboard.

The truth is, although becoming a full-time developer can take quite a bit of dedication, learning how to write code can be easy. As more of our life touches computers, learning to write code to control them can enhance any career, no matter how nontechnical it may seem. An elementary school teacher might make a website to help students learn their vocabulary. An accountant could automate calculations that normally have to be done by hand. A parent could create a home inventory system to help with generating grocery lists. Nearly every profession and hobby can be enhanced through learning to program.

To put it simply, computers are stupid. Without human input, they don’t know what to do. Code is a set of instructions that tells the computer not only what to do, but how to do it. Everything on your computer, from the largest applications (such as Word and video games) to the smallest (such as a calculator), is based on code.

Most code on your computer will be compiled already as an .exe or .app file. For the exercises in this book, we’ll either be running them from a file or using the interpreter (which we’ll get to in Hour 1, “Installing and Running Python”).

Why Python?

Python is a language that is lauded for its readability, its lack of fussiness, and how easy it is to teach. Also, unlike some languages that are created specifically for teaching, it’s used in countless places outside of the classroom. People have used Python to write everything from websites to tools for scientific work, from simple scripts to video games. The following is a non-exhaustive list of programs written in Python:

Image YouTube—A popular site for viewing and sharing videos.

Image The Onion—A parody news site.

Image Eve Online—A video game set in space.

Image The Washington Post—The website runs off of Django, a framework written in Python.

Image Paint Shop Pro—An image-editing software package.

Image Google—A significant number of applications at Google use Python.

Image Civilization IV—A turn-based simulation game.

Python may appear simple, but it’s incredibly powerful.

Getting Started

Before we get started, let’s go over a list of some things you’re going to need. You absolutely must have all these things before you can start learning Python. Here’s what you will need:

Image Admin access—Python doesn’t require a very powerful computer to run, but you will need a computer that you have permission to install things on.

Image Internet access—We’re going to be downloading installers, and, later on, talking to web services. It doesn’t need to be a fast connection, because many of the items we’ll be downloading are rather small.

Image A computer—It doesn’t need to be brand new, but the faster your computer is, the faster your code should run. A computer built in the past five years should be fine.

Image Space—A dedicated workspace can greatly enhance your ability to pick up new concepts. It should be free from distractions, such as TV.

Image No distractions—It’s almost impossible to learn something new if you have family members interrupting you, phones buzzing, or a TV blaring in the background. A good pair of noise-canceling headphones can be a wonderful asset—if you can’t get rid of people and ambient noise.

For most people, the last two items can be the most difficult to get in place, but they’re invaluable. Not only will you need them while learning, but you’ll need them once you’re done with this book and moving on to your own projects. Writing code is a creative endeavor, and requires time and space to do.

How This Book Works

Each chapter is meant to be completed in one hour or less. That includes reading the text and doing the exercises. Ideally, the exercises should be done directly after reading a chapter, so try to set aside time when you not only can focus, but have access to your computer. Not every chapter will require Internet access (those that do will warn you before you dive in).

It may be tempting to dive in to the next chapter after finishing one, but try to give yourself a break. Your brain needs time to integrate the new information, and you need to be rested before diving into more new material.

What to Do If You Get Stuck

There is one thing that applies to every person who writes code: You will get stuck. Sometimes a new concept doesn’t seem to be clicking. Sometimes an error won’t go away. There are days when everything you touch seems to break.

The key to getting past days like these is to not give in to frustration. Get up, move away from the computer, and go for a walk. Make a cup of tea. Talk to a friend about anything but your misbehaving code. Give yourself a chance to unwind.

When you’ve given yourself some space from the problem, do a quick self-assessment. Are you tired? A tired developer is a bad developer, no matter how experienced he or she is. Sometimes a bit of coffee helps, but most of the time what you need is some sleep.

If you’re not tired, try re-reading the chapter. It might be time to break out the highlighters or take notes. Are some of the terms unfamiliar? Try searching for these terms online.

Is the code not working? Sometimes, you need to delete what you have (or save it in another file) and try again. Later in the book, we’ll talk about better ways to debug your code, but rest assured, every developer has had to toss code at some point in his or her life.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.23.147