Python is now the most popular introductory language at American colleges, a recent Association for Computing Machinery study reports.
In an analysis of the top 39 computer science departments as ranked by U.S. News in 2014, the general-purpose programming language has replaced Java as the budding computer scientist’s first exposure to writing code. Eight of the top 10 CS departments (80%), and 27 of the top 39 (69%), teach Python in their introductory courses.
Invented 23 years ago, Python’s discovery as a great tool for first-timers has been more recent. The beginner-oriented Raspberry Pi has certainly influenced Python’s new role as a teaching tool, but also its increasing adoption at organizations like Google, Yahoo and NASA that make it valuable to know even after a programmer is no longer a beginner. In modern times, it has routinely been ranked as one of the eight most popular programming languages since 2008.
Perhaps not so coincidentally, Python is my first programming language, too. I’m halfway through Zed Shaw’s Learn Python The Hard Way on my road to mastery. And in this liberal arts student’s studies, I’ve noted a few key characteristics that make Python easy to grasp.
Here are some of the reasons Python makes a great first programming language.
Very Minimal Setup
To show you just how easy it is to get started with Python, let’s literally get started with Python.
On a Mac, find your Terminal program and open it. On a PC, find the PowerShell program and open that. It’ll be a blank box where you can write in text prompts.
Do that now. Write in the word “python” and hit Enter. You should see something like this:
If you don’t see that and instead see the words “python is not recognized” or something similar, you need to download Python, Python 2 to be exact, and try again.
Either way, it only takes a single word to get your computer to run Python. It doesn’t get much simpler than that.
It’s Written In Plain English
Python is so easy that we’re going to write our first Python program right now.
If you’re still running Python from the last section, type CTRL-Z on a Mac or “quit” on a PC to exit.
Now create a new blank Python file using Nano, a basic command line text editor. All you have to do is give it any name and end it with the suffix “.py” so your computer understands it is a program intended to be read by Python. The “nano” prompt simply opens it in Nano.
This is the most basic Python program you can write, a command that simply prints the words “Hello world” on your computer screen. Compare it to Java and C’s “Hello World” programs, which are each several lines long. There’s no weird syntax, no cryptic variables. Anybody can look at this one line and figure out what it does.
Save, and then run the file with the “python” command. It’ll print your program:
Errors Appear On Runtime
When you’re learning something for the first time, you’re inevitably going to make mistakes. Python makes it easy to identify and fix these mistakes immediately. That’s because Python displays errors at run time, instead of simply failing to compile the program.
Open up example.py, the program we just wrote before and intentionally make an error. Here, I’ve omitted a necessary quotation mark.
When I try to run the program, Python tries to point out where I went wrong:
Instead of displaying a blank screen where your program should have been, Python will run your buggy program and try to help you troubleshoot it.
Shallow Learning Curve
I began coding Python last week with the program above. A few days later, I’ve programmed my own basic text editor and calculator using Python.
Because Python has so little overhead and excess code, it becomes easy to grasp continually more difficult concepts since they mimic English sentence structure we’ve seen before.
We just built the most basic program possible. But even just knowing what you know about Python now, I bet you can take a guess as to what the following program does:
I’ll run this program using the Python command.
Sure enough, it lists how many students and teachers there are, and does a basic division problem for us. Did you guess correctly?
For the reasons above and many more that more experienced Python programmers can explain better than I, Python makes a great first programming language, especially if you don’t really consider yourself the math and science type. It’s really no surprise that American universities have come to the same conclusion.
Logo via the Python Foundation