Preface
This simple book is meant to get you started in programming. The title says it’s the hard way to learn to write code but it’s actually not. It’s only the «hard» way because it uses a technique called instruction. Instruction is where I tell you to do a sequence of controlled exercises designed to build a skill through repetition. This technique works very well with beginners who know nothing and need to acquire basic skills before they can understand more complex topics. It’s used in everything from martial arts to music to even basic math and reading skills.
This book instructs you in Python by slowly building and establishing skills through techniques like practice and memorization, then applying them to increasingly difficult problems. By the end of the book you will have the tools needed to begin learning more complex programming topics. I like to tell people that my book gives you your «programming black belt.» What this means is that you know the basics well enough to now start learning programming.
If you work hard, take your time, and build these skills, you will learn to code.
Acknowledgements
I would like to thank Angela for helping me with the first two versions of this book. Without her I probably wouldn’t have bothered to finish it at all. She did the copy-editing of the first draft and supported me immensely while I wrote it.
I’d also like to thank Greg Newman for doing the original cover art, Brian Shumate for early website designs, and all of the people who read this book and took the time to send me feedback and corrections.
Buy The Python 2 Course
When you buy directly from the author, Zed A. Shaw, you’ll get a professional quality PDF and hours of HD Video, all DRM-free and yours to download.
The Hard Way Is Easier
With the help of this book, you will do the incredibly simple things that all programmers do to learn a programming language:
That’s it. This will be very difficult at first, but stick with it. If you go through this book, and do each exercise for one or two hours a night, you will have a good foundation for moving onto another book about Python to continue your studies. This book won’t turn you into a programmer overnight, but it will get you started on the path to learning how to code.
This book’s job is to teach you the three most essential skills that a beginning programmer needs to know: reading and writing, attention to detail, and spotting differences.
Reading and Writing
If you have a problem typing, you will have a problem learning to code, and especially if you have a problem typing the fairly odd characters in source code. Without this simple skill you will be unable to learn even the most basic things about how software works.
Typing the code samples and getting them to run will help you learn the names of the symbols, get familiar with typing them, and get you reading the language.
Attention to Detail
The one skill that separates bad programmers from good programmers is attention to detail. In fact, it’s what separates the good from the bad in any profession. You must pay attention to the tiniest details of your work or you will miss important elements of what you create. In programming, this is how you end up with bugs and difficult-to-use systems.
By going through this book, and copying each example exactly, you will be training your brain to focus on the details of what you are doing, as you are doing it.
Spotting Differences
A very important skill (that most programmers develop over time) is the ability to visually notice differences between things. An experienced programmer can take two pieces of code that are slightly different and immediately start pointing out the differences. Programmers have invented tools to make this even easier, but we won’t be using any of these. You first have to train your brain the hard way, then use the tools.
While you do these exercises, typing each one in, you will be making mistakes. It’s inevitable; even seasoned programmers would make a few. Your job is to compare what you have written to what’s required, and fix all the differences. By doing so, you will train yourself to notice mistakes, bugs, and other problems.
Do Not Copy-Paste
You must type each of these exercises in, manually. If you copy and paste, you might as well not even do them. The point of these exercises is to train your hands, your brain, and your mind in how to read, write, and see code. If you copy-paste, you are cheating yourself out of the effectiveness of the lessons.
Using the Included Videos
Learn Python The Hard Way has more than 5 hours of instructional videos to help you with the book. There is one video for each exercise where I either demonstrate the exercise, or give you tips for completing the exercise. The best way to use the videos is to attempt or complete the exercises without them first, then use the videos to review what you learned or if you are stuck. This will slowly wean you off of using videos to learn programming and build your skills at understanding code directly. Stick with it, and slowly you won’t need the videos, or any videos to learn programming. You’ll be able to just read for the information you need.
A Note on Practice and Persistence
While you are studying programming, I’m studying how to play guitar. I practice it every day for at least two hours a day. I play scales, chords, and arpeggios for an hour and then learn music theory, ear training, songs, and anything else I can. Some days I study guitar and music for eight hours because I feel like it and it’s fun. To me repetitive practice is natural and just how to learn something. I know that to get good at anything you have to practice every day, even if I suck that day (which is often) or it’s difficult. Keep trying and eventually it’ll be easier and fun.
Between the time that I wrote Learn Python The Hard Way and Learn Ruby The Hard Way I discovered drawing and painting. I fell in love with making visual art at the age of 39 and have been spending every day studying it in much the same way that I studied guitar, music, and programming. I collected books of instructional material, did what the books said, painted every day, and focused on enjoying the process of learning. I am by no means an «artist», or even that good, but I can now say that I can draw and paint. The same method I’m teaching you in this book applied to my adventures in art. If you break the problem down into small exercises and lessons, and do them every day, you can learn to do almost anything. If you focus on slowly improving and enjoying the learning process, then you will benefit no matter how good you are at it.
As you study this book, and continue with programming, remember that anything worth doing is difficult at first. Maybe you are the kind of person who is afraid of failure so you give up at the first sign of difficulty. Maybe you never learned self-discipline so you can’t do anything that’s «boring.» Maybe you were told that you are «gifted» so you never attempt anything that might make you seem stupid or not a prodigy. Maybe you are competitive and unfairly compare yourself to someone like me who’s been programming for more than 20 years.
Whatever your reason for wanting to quit, keep at it. Force yourself. If you run into a Study Drill you can’t do, or a lesson you just do not understand, then skip it and come back to it later. Just keep going because with programming there’s this very odd thing that happens. At first, you will not understand anything. It’ll be weird, just like with learning any human language. You will struggle with words, and not know what symbols are what, and it’ll all be very confusing. Then one day BANG your brain will snap and you will suddenly «get it.» If you keep doing the exercises and keep trying to understand them, you will get it. You might not be a master coder, but you will at least understand how programming works.
If you give up, you won’t ever reach this point. You will hit the first confusing thing (which is everything at first) and then stop. If you keep trying, keep typing it in, trying to understand it and reading about it, you will eventually get it. If you go through this whole book, and you still do not understand how to code, at least you gave it a shot. You can say you tried your best and a little more and it didn’t work out, but at least you tried. You can be proud of that.
A Warning for the Smarties
Sometimes people who already know a programming language will read this book and feel I’m insulting them. There is nothing in this book that is intended to be interpreted as condescending, insulting, or belittling. I simply know more about programming than my intended readers. If you think you are smarter than me, then you will feel talked down to and there’s nothing I can do about that because you are not my intended reader.
If you are reading this book and flipping out at every third sentence because you feel I’m insulting your intelligence, then I have three points of advice for you:
- Stop reading my book. I didn’t write it for you. I wrote it for people who don’t already know everything.
- Empty before you fill. You will have a hard time learning from someone with more knowledge if you already know everything.
- Go learn Lisp. I hear people who know everything really like Lisp.
For everyone else who’s here to learn, just read everything as if I’m smiling and I have a mischievous little twinkle in my eye.
Buy The Python 2 Course
When you buy directly from the author, Zed A. Shaw, you’ll get a professional quality PDF and hours of HD Video, all DRM-free and yours to download.