How to Learn Python
Learning Python
A common mistake when learning to program is trying to commit everything to memory.
Here’s why it isn’t a good idea to simply try to memorize lists of functions or chunks of code.
- There’s simply too much to memorize. Python 3.8 itself has 69 built-in functions. Add a few common libraries, and you might find yourself trying to memorize hundreds of pieces of information.
- Even if you memorized all the methods in a library, it still wouldn’t get you very far. Programming isn’t about rote memorization; it’s about applying the right tool at the right moment.
- There are plenty of resources that make it unnecessary to memorize everything. Google and StackOverflow are essential tools in any programmer’s toolkit.
Focus on concepts
Ultimately, the key to being a good programmer is to know that a function/concept/technique exists, rather than the nuances of how to use it
Example:
You have a string containing a name and an address.
1customer_info = 'Sam Parry: 425 Bluster Drive'
You want to separate the name from the address. Now, you could start going through every function you know to see if any of them fit this situation. You might find the one you need... or you can go the faster route and just search for “python how to break up a string,” and you’ll be reminded of the split()
method.
1customer_info = 'Sam Parry: 425 Bluster Drive'2customer_info = customer_info.split(': ')3print(customer_info)
1['Sam Parry', '425 Bluster Drive']
What was crucial here?
- You recognized the value of
customer_info
as a string. - You remembered how to call a method on its object (
customer_info.split()
). - To use the results further, you’ll need to remember how lists work.
Understanding the principles of programming makes it easier to see how they apply in various situations. Conversely, if you only know there’s something called split()
, you’re going to have a hard time performing list manipulations.
So I don’t need to memorize anything?
A talented coder will have a lot of useful functions and methods at their fingertips. They’ll be able to write programs quickly because they won’t stumble over syntax. But this means their skills have been fine-tuned, first, you need to lay the foundation.
What to do instead of just memorizing
Practice more — this will help you think like a coder
Find exercises related to higher-level concepts: loops, common data types, etc.
Plan your programs before writing them. Write in plain text what your program should do and in what order. Then try writing pseudocode of your program that you can later replace with a working Python code
Read other people’s code and figure out what each line/section is doing
Look up anything you’re not sure about on Google, StackOverflow, docs
Review your notes
Recall code that you read in recent material — can you reconstruct the steps in your head? Focus on concepts, not syntax
If you find that you need to look up the same pieces of code several times, consider creating a library of code snippets on Github Gist