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
- PIL and cv2
- beautifulsoup, selenium, urllib, and scrapy
- flask, django, jinja2
- tkinter, pyqt, pyWX
Packages Encouraged while Learning
- os, sys, and argparse
- json, csv, and pprint
- datetime and time
- math, statistics, and random
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 in lists of to write efficient code. If you are feeling ambitious, use random and for loops to estimate the probability of a random sodoku 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.