Learning Python? Start small.

April 23, 2019

I’ve done a few tutorials, but when I try to build something on my own, I hit a wall. It felt like I would never get away from how-to guides and be able to build something independently!

It’s really disheartening and frustrating to complete a tutorial, feel like you understand how Python works, only to realize you don’t know enough to build your own application.

This applies to any programming language or framework! Although the examples I’ll give in this article are in Python. When you first start learning to code, you’re tied to tutorials to learn how the language works.

The real challenge is letting go of those tutorials and charting your own course. When I tutor new coders and people starting to learn Python, I see this challenge all the time.

Learning a language is like learning to swim

Before I learned to swim, I’d always stay in the shallow end of the pool. Or, I would hold on to the edge of the pool the entire time I was in the deep end.

I quickly learned that you don’t learn to swim by holding on to the edge! You have to spend time away from the edge before you’ll ever learn.

The same is true for learning any skill, but especially for coding tutorials. They help you safely get into the water. And they teach the basic concepts of coding. But to really learn, you’ll need to venture away from them once you have a basic understanding.

Start really small

That said, you also don’t learn to swim by dropping yourself in the middle of a lake! You will be setting yourself up for failure if you are too ambitious at the beginning.

Instead of trying to build a full-featured, perfect application for your first project, I recommend building tiny, single-feature programs to help you familiarize yourself with the language.

These should be tiny, throwaway, no-stakes experiments that allow you to play with the concepts you’ve learned so far.

There’s no design questions or need for optimization. You won’t use these apps after you’ve built them (likely), but they exercise your independent coding skills, instead of your tutorial following skills.

If you mess something up badly, the mini-app should be so small and insignificant that you can easily delete the entire thing and start over.

How small?

Try these tiny experiments:

  • Print “Hello World” to the console
  • Create variables hello and world that are strings and then print both variables to the console
  • Create a variable name that accepts an input from the user and then prints “Hello name” to the console
  • Make the above app print “Hello world” if the user doesn’t enter a name
  • Create a class Person with an attribute name . When the user provides their name, create a new Person and then print “Hello Person.name
  • Create a static dictionary like {'Alice': 1, 'Bob': 2} and print all the key-value pairs to the console using a for loop, then do the same thing with a while loop
  • Turn your key-value printing code into a reusable function called print_dictionary(dictionary)
  • Create a function that looks up a provided key in the dictionary and adds 1 to that key’s value (e.g.def add_one(key, dictionary) )
  • Modify the function so that you can provide the number to add (e.g. def add_anything(key, amount, dictionary))
  • Make a counter, initialized to zero. Then accept user input, add the user input to the counter, and print the new counter total
  • Create a loop so that the counter continues asking for user input until it reaches a certain number
  • In your counter, use a try/except block to catch user inputs that aren’t numbers
  • Turn the counter into a class with an attribute of value
  • Add another attribute num_inputs to the Counter that counts how many times the user has input a number

Make it incremental

You see where I’m going with this. Start with something tiny and trivial for you to implement. Then, dig a little deeper. Make it one level more complex.

These aren’t full-blown applications, but they are the path from “stuck in tutorial mode” to “confident with the basics.” They are the drills that will solidify the knowledge in your brain and make the basics easy to implement in the future.

Maybe you’re more of an intermediate Python developer and these examples I’ve given seem too easy. Good! It should only take you a few minutes to implement them then.

After you’re done, find something else about Python that makes you uncomfortable. Try to build something tiny with it. Shine a light in the corners of your understanding. Always keep pushing the edge.

Update (4/24/19): I’ve thought of some ideas for intermediate Python devs: Build mini-apps that use collections, requests, generators, decorator functions, context managers, unittest/pytest, deep copies, try/except/else/finally, etc.

There’s always more to learn!

Small is how you get better, even if you’re an expert

Even Guido van Rossum himself doesn’t have a perfect command of every feature, library, and potential application of Python. It would be impossible for any one person to completely master a language.

What I’m trying to expose here is a method for learning. Incrementalism is the only way to get better. Keep finding new stuff to try every day, and over time you’ll be amazed how far you’ve come.

Experienced developers know that making software is nothing but constant learning. Languages and frameworks go out of style and you’ll need to learn new ones. You might have a new application that requires new tools. For almost anything anyone builds, there’s a ton of learning.

There’s not a developer in the world who writes perfect code the first time without having to look anything up. We’re all constantly learning in small ways. It’s what makes coding so fun!

Practice makes perfect

Practicing small skills is the path to mastery.

Coding is a skill like any other.

Just as a chef must spend years in the kitchen, a pianist must spend thousands of hours at the keys, and an athlete must drill day in and day out; so too must developers practice honing their skills.

This story is inspired by Dave Ceddia’s article about React. Highly recommend.

About Bennett

I’m a web developer building things with Python and JavaScript.

Want my best content on web development and becoming a better programmer?

I share my favorite advice with my email list — no spam, nothing sales-y, just useful content.

Join 500 other developers currently in my email series.


Profile picture

I write something new every day for 2k software developers. You should sign up for the daily email.

© 2024