I was just browsing Quora after coming back from dinner, and there were lot of night owls asking “How do I learn XYZ from scratch?”
Naturally, I swooped in to assist with the Python-related questions. Believe it or not, there is a wrong way to learn Python. I have seen many people of many different ages get burnt out on learning Python because they went about it all wrong. The key to learning Python is to do just that, no more, no less.
Learn Python, not Libraries
Python packages can both extend its functionality and modify the way it is written. There are a ton of packages available, and some of them are so large and complex that they require a course of their own. I often see self-educators get hung up on package-specific syntax while trying to learn vanilla Python.
People can get burnt out on Python when they try to learn it in conjunction with packages that alter its syntax and behavior. Thus, for a self-educator’s first few projects, I recommend they avoid complex packages to better familiarize themselves with vanilla Python.
Packages to Avoid While Learning
- numpy and pandas
- matplotlib
- PIL and cv2
- beautifulsoup, selenium, urllib, and scrapy
- flask, django, jinja2
- tkinter, pyqt, pyWX
Packages Encouraged while Learning
- os, sys, and argparse
- re
- json, csv, and pprint
- datetime and time
- math, statistics, and random
Case Study
I was once tutoring a Master’s candidate at the University of Virginia how to use Python. She was interested in learning Python to interface with the OpenCV API via the cv2 module. I had recommended her many educational resources from complete beginner texts to advanced OpenCV texts.
After a week of self-teaching, she had not made much progress in learning Python, mainly because she was trying to debug a specific script she found online. The script would read images via OpenCV’s cv2, then use matplotlib to display the images. The script used a strange matplotlib function I had never seen before for displaying the images. So, when she came to me with the error, I had no idea how to fix it. But… I did know how to accomplish the same thing with purely cv2.
All the while, she had learned nothing about Python itself, because she was busy trying to debug a matplotlib function. Obviously, her time would have been much better spent reading the first few chapters of an introductory Python book. I wouldn’t say that this student was unmotivated, rather that she was working a little too hard to fix an archaic and unnecessary matplotlib function.
So, we had to go back to the basics (where we should have started). This was no big deal, but it shined a light on how cavalier attitudes towards learning often do more harm than good.
Conclusion and Project Ideas
Keen readers may have noticed that all of the packages listed as “encouraged” for learning are shipped with vanilla Python. There is a reason for this. The core developers only write and accept highly Pythonic packages for distribution with the base environment.
Don’t be afraid to get your hands dirty with educational projects. Even if they don’t do anything useful or new, they are important to your education in a language where almost everything has been packaged already.
- Summary Stats. Read in a csv file supplied to the command line via argparse and os, read the csv file into a list of lists with csv, generate summary statistics with math and statistics, then print a friendly table of summary statistics with pprint or string formatting.
- Book Analyzer. Read in Romeo and Juliet as an enormous string using os and with statements, then use re to count occurrences of common words or letters. Print statistics about the frequencies and see if they follow to Zipf’s Law.
- Sudoku Checker. Given a 9×9 list of numbers (organized as a list of lists) check if a Sodoku row, column, square, and board are valid. Use random to generate integers for your board. Experiment with slice notation and lists of lists to write efficient code. If you are feeling ambitious, use random and for loops to estimate the probability of a random Sudoku row, column, square, and board being valid under various conditions.
Once you are comfortable with the core tenets of Python, and the Pythonic elements of the syntax, you will have an easy and productive time exploring its best libraries.
Hi Chris, thank you for the tips! I’ll be sure to take them in consideration while learning Python.
I’m only beginning, but I do have experience programming from my college days (5~8 years ago), mainly C and C++, but also a bit of Java, Delphi, COBOL. So, a lot of concepts aren’t foreign to me.
I was never into math and statistics, so I’ll avoid getting into Data Science/Machine Learning until I feel I’m comfortable with several Python projects. What do you recommend as learning steps, from simpler to more complex projects?
Python (vanilla) -> Web Development -> Games -> Data Science?
Thanks!
Along the lines of the post, I think any of these paths are fine:
Python (vanilla) -> Web Development -> ???
Python (vanilla) -> Games -> ???
Python (vanilla) -> Data Science -> ???
You’ll end up exploring new packages and learning package-specific syntax to do any of these tasks, so learning one does not necessarily preclude or enable another. Best of luck in your learning!
I am a CSE student who has been programming for quite some time(5-7 years, although no professional experience). I don’t know python, but neither am I a newbie to programming. Should I still avoid those libraries, or should I learn stuff as and when needed?
The only time I have used python was to create a small script for a RESTful API using flask, but I won’t say I learnt anything much as it was hardly even 20-30 lines of code, and I only looked up syntax as needed.
Hi Aditya,
There was some good discussion on Reddit about this article, and a lot of people concluded that this applies most to people who are new to programming in general.
I say, see how you do. If you are confused, you’ll know how to ratchet it back to get your head around the language.
Best,
Chris