How To Practice Python

You probably know that the best way to practice Python is to build it into a daily habit — the same way you get good at anything. Continuing a daily practice is much easier if you learn a little about how habits form. The trick is to do things that enable the same processes that form all habits.

Python Habits Are No Different From Other Habits

Before we begin, I want to give a huge shout-out to the giant in the modern field of habit formation, James Clear. I have used his technique to average over 700 words per day published on this blog over the last four weeks or so. That’s pretty slow by professional writer standards, perhaps, but I’m doing it while working full time, and it’s been awhile since I’ve written consistently. So I’m pretty happy with the results.

You can blame it on the cold here in North Carolina. I ordered the audio version of his book, Atomic Habits, to have something to listen to on the treadmill, so I wouldn’t get bored.

This article on Python practice, then, owes a debt to that book, but I can also add my recent experiences on this blog into the mix. In addition, I want to draw on my experiences on what I did as a self-taught programmer. Python wasn’t the first language I seriously undertook to learn. It was C, which I learned way back in 1990. Yes, 1990. George Bush was in office. Not the second one who flubbed his sentences — the first one, who had been CIA director.

The internet was brand new, but most of us hadn’t heard of it. You can imagine wooly mammoths walking around, if helps to paint a picture.

Setting Up Your Environment for Success

James Clear spends a fair amount of time on the idea that your habits should be easy, and setting up your environment in advance is part of the way to do this.

The first thing you’ll need is some Python material to learn from on. Input can be either a book or an online course, depending on your preferences. Back when the wooly mammoths roamed around, we didn’t have a choice, really. Books still work if you want something quiet and portable that you can learn from on your lunch break — I did a lot of that when I was learning C, and it helped a lot. The other advantage to books is that they force you to type the examples. Yes, it’s true that experienced developers copy and paste a lot of stuff, but as a beginner you need some basic finger memory.

If you are a beginner, there are two resources that my family owns and that I know beginners have used successfully. My wife used both of these, and in the case of the Python Crash Course, I know one other strong beginner who rated it highly as well.

  • Python Crash Course: A Hands-On, Project-Based Introduction to Programming — This is a great beginner Python book that is a combination of a language tutorial plus three engaging projects at the end: Alien Invasion (a computer game), a data visualization project using matplotlib, and a web project using Django.
  • Python Programming: An Introduction to Computer Science, Third Edition — This is a somewhat more formal book, but as the name suggests, it gives a good introduction to many of the common basic algorithms, techniques, and problems that programmers should be familiar with. This book has lots of great practice exercises to hone your skills. (On a personal note, it reminds me of a similar text I used to teach myself C, my first programming language).

Whether you pick an online course or a book, it’s good to find a resource that has a mix of both information and exercises for you to do. Those who are more advanced may already know how to go through this process, and work with materials appropriate to their level. For beginners practicing Python, I recommend a mix of:

  1. Copying working examples from a trusted source. Making sure you can get these to work is a good first step that will help you troubleshoot simple errors.
  2. Working with exercises provided in the book or video course. This will reinforce the material.
  3. Doing your own exercises and practice. It’s important that you give yourself LOTS of freedom here. It doesn’t have to be fancy or something you publish. Anything that helps you better understand or practice the things you’re learning from your book or course is a win. If something is hard, practice the heck out of it until it’s easy. If you want to explore something unrelated, do it!

Items one and two on the list above are about following a teacher and being systematic about it. Item three is about engaging your natural curiosity and ability to learn to serve your activity. I think you need both. One and two give your learning a structure that it won’t have if you just ask around on Twitter. Three makes it fun!

You’ll also need to install a Python IDE. If your book or online course doesn’t recommend a specific one, PyCharm (the Community Edition is free) and Spyder are good choices. You’ll also need to install a recent Python version separately if you choose PyCharm.

(At the risk of confusing you: there are many other IDE choices depending on your preferences — I asked newcomers to weigh in on this Reddit thread, and the responses were very helpful!)

The Python Practice Implementation Intention

This is a critical step. Don’t skip this.

One of the things that habit researchers have found is that setting up a definite cue for when you’ll practice your habit is crucial to getting the habit established. A cue can be either a time of day, or an event that already happens. It also helps very much to tie it to a specific place, so it will be obvious when it’s time to start.

For me, the cue to start writing is that I’ve finished my breakfast and other morning routine and have walked into “the study” (the room where my computer is). So my implementation intention could be written as, “After my morning routine is over, and I’ve walked into the study, I will write.” I could also write this as: “At ___ AM, I will write,” but I prefer a cue that’s flexible as to time. Some days I’m up at four and in the study by five. Other days I sleep in a bit more. But I almost always finish my other morning routine first other tasks first, then write before doing other things.

Your practice time should have a similar cue. It helps to write it down.

START!

You started making it easy by setting making an implementation intention. This gave you a cue for where and when to start. Having your IDE and your input ready to go mean you’ll be ready to go when you start, so that helps to make it easy, too. Now, sit down with your trusted input, your IDE open, at the time and place you specified, and START!

Here’s why starting is so important that I felt it deserved the header and bold letters and capitals and so forth. A lot of the literature on reaching goals is top down — it focuses on making our goals “S.M.A.R.T.” and a lot of other arm waving. But goals don’t matter. Starting matters.

Starting matters for several reasons. First, it validates your implementation intention, so even if you don’t hit whatever your goal is for the day, you already can feel good about showing up. Secondly, until a habit becomes automatic and therefore firmly entrenched, it is often much easier to continue doing something than to start doing it. Finally, starting matters because it’s logically impossible to hit whatever that goal is if you don’t start. However long you want to practice Python on a given day, you can’t hit that goal if you don’t start.

This topic is actually very near and dear to me, especially today. Remember I said that I’ve been averaging over seven hundred words a day recently? Well, last night I didn’t sleep well, and so I woke up with that sort of fuzzy-headed stupidity that I get when I don’t sleep well. The last thing I wanted to do was to start writing, but I knew that if I didn’t start, my score for the day would be zero. If I didn’t start, I wouldn’t continue.

Making Your Python Practice Easy

OK, you have everything you need — the tools to practice, and you’ve started. How much should you do? That’s a tough question to answer. When I was learning to code with the wooly mammoths dancing outside my window, I did a lot, probably at least two or three hours most days, and many days much more than that. However, James Clear recommends picking a target that’s easy to do, because it helps with starting. Don’t do 100 push-ups — do one push-up. Then keep going. Don’t spend an hour at the gym, just go to the gym. That sort of thing.

Based on my current experience with the writing habit, I think I’d recommend something between three hours of effort and “one push-up’s worth”. I believe an ideal goal is something that’s easy enough that you can do it even when it’s not your best day, but substantial enough that you’ll feel a slight dopamine hit of accomplishment after you’ve done it. I mentioned earlier that my average is over 700 words per day, but my goal is actually only 500 words per day. For me, that’s a target that’s not utterly trivial, but still quite easy to hit. Folks who do “100 days of code” strive for 1 hour per day for 100 days. That sounds about right.

Build In a Reward for Your Practice

When I was starting the writing habit, I thought I’d get a jar of chocolate kisses and give myself one after so many words. Although I reserve the right to do that (since I love my chocolate), I haven’t yet found it necessary. One thing I that I have done, though, is to jot down my count for each day after each writing session. So if you’re doing something like 100 Days of Python, the equivalent “reward” you would build in might be jotting down the minutes you spend in a spreadsheet or journal (recording your “count”, which in this case is a time period).

When writing, I also to track the published articles when they’re ready. In this case, the 100 Days of Python equivalent might be adding a link to the day’s progress on a GitHub page, or doing a post on Twitter and LinkedIn, or what-have-you.

Tracking your time and publishing your milestones should be done as soon after you practice some Python as possible. In my writing habit example, I may write in several sessions, but I’ll track the cumulative count after I write even just a few words. The reason for this is the same reason why you give a dog a treat immediately after they do what you want. You can’t teach a dog to sit by rewarding him the next day and telling him he did a great job sitting yesterday!

Other Rewards

Unlike other animals, however, humans and other primates also benefit from intrinsic and social rewards. For example, in some clever research done in London, chimpanzees enjoyed solving puzzles whether a food reward was present or not. Similarly, in the case of my writing habit, it helps tremendously that I enjoy writing. I also very much have enjoyed learning to code over the years, both in my first language and subsequently.

Another reward you may get is social validation. In my case, it doesn’t hurt that the community has been very supportive and non-stingy in their praise. (People are much harsher on YouTube, I’m told!)

As important as these rewards are — they’re different from the reward I give myself of writing down my count and tracking my progress, in that they’re not strictly speaking under my control. I may not enjoy writing every day — certainly it’s less fun when I’m either tired or mentally distracted by some shiny new bauble.

The same is true of learning to code — your motivation on a given day will depend on your energy level and other conditions of your life. It also depends a lot on whether your attitude to the task. You may enjoy learning Python for its own sake, or you may only see it as a distasteful prerequisite to some other goal like becoming a machine learning expert or getting a passing grade in a class.

This is one of the reasons I stressed making up your own exercises. It’s not just to reinforce the exercises you practice “to get through the book”, it’s also to engage your curiosity and sense of fun. This matters a lot, because the task is the same either way. A death march and a walk in the park are both a way to move your feet, but I know which one I’d rather be on.

As for social rewards, this falls squarely into the category of “things beyond our control”. There seems to be general agreement among the Stoic Greek philosophers and the Buddhist tradition that because our major focus should be on elements we can control to some extent, people’s opinions of us are none of our darned business. Meantime, in 2022, sophisticated AI algorithms are capitalizing on the primitive parts of our brain that just can’t resist being “liked” for our #hashtag-#friendly ideas. So perhaps it’s best just to consider social rewards as an occasional dessert, not as a satisfying main course.

Final Thoughts

Of course, it stands to reason this post would be about Python — you’re reading a Python blog, after all. But I hope I’ve made it clear by now that to be successful in your Python practice, you have to tap into the process of habit formation that’s universal in humans and animals. Perhaps the only thing uniquely human about this is the explicit framing of an implementation intention — but even there, all we’re trying to do is set up a cue in our environment to begin our practice.

What is specific to Python is that — as programming languages go — it’s perhaps one of the easiest to learn and be successful. Beyond that, the rest of this article has been about trying to make it even easier.

  • We set up the environment for success by having our inputs and our IDE ready to go, because having to think about what we’re working on next takes time and slows us down.
  • We start because it’s easier to keep going on something than it is to shift gears.
  • We make our practice easy as a reward for starting, but we make it challenging enough to build in a second reward for finishing and to keep things interesting.
  • Finally, we build in other rewards, for the same reason one gives a dog a treat after a successfully executing a command: what gets rewarded persists.

I wish you every success, and I hope that as you work your exercises or work on more advanced projects, that you’ll let me know about them. You can leave a comment here about your practice exercises or connect with me on Twitter, LinkedIn, or Reddit. I look forward to hearing from you!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.