Why Learn Python?

Reading Time: 11 minutes

This quarter I am teaching a class on Python programming. I get a limited amount of time with the students, so I had to get pretty ruthless in my decisions about what to cover and what not to cover. In particular, I skipped why they should learn Python, because in their program, they’re required to. Ta-da!

That said, I felt unsatisfied with the idea of barging ahead on the what and how questions without providing any explanation about why. Furthermore, “you’re required to” is only sufficient reason to learn Python in a very specific situation. It does not cover most people who are considering learning Python, or who have committed to learning to program but who haven’t quite chosen a first language yet.

So I wrote up my thoughts on the question. I also had a more selfish reason for writing up these thoughts, which is that I frankly don’t like many of the explanations I’ve seen. First, they tend to center some inaccurate assumptions about how the tech industry works. Second, they tend to accidentally detract from the Python language community’s stated goals of accessibility, inclusion, et cetera. Third, they tend to overstate Python’s value in comparison to other programming languages—in particular, claiming Python is good for things that it just isn’t good for and you probably should pick a different language.

But I’m getting ahead of myself. Without further ado, here’s “Why Learn Python?” Video on top and text below.

Python is a great programming language to learn, BUT…

So are lots of other programming languages like Java, Ruby, JavaScript, Swift, Kotlin, Golang, Rust, or Haskell.

And also, you don’t have to choose just one. You can learn as many programming languages as you want over the course of your career. So let’s focus the question: why choose Python as your first or second programming language?

Many introductory texts about Python address this question, so we’ll address it too.

But before we do, let’s talk about computer science.

Specifically, about the role of perspective in computer science.

He’s a little confused, but he’s got the spirit!

See, computer science is unlike natural science.

Chemists, physicists, and biologists study phenomena governed by universal (except at the extremes) laws of physics, all of which existed long before humans got to this planet.

In computer science, everything we use—from frameworks to programming languages to the computer itself—some human(s) created.

That means two things for computer systems:

  1. Computer systems are inconsistent. One person did it a different way than another person. This means that inductive reasoning doesn’t necassarily work on code bases: one strategy does not translate across code bases the way that, say, the acceleration of gravity acts on every object on Earth.
  2. Every single computer system has a perspective, because it was created by a person or persons who had a perspective.

So, in any code base, to reason about how things work and why, it’s helpful to understand the perspective of its authors.

So…what is the perspective of Python?

Conveniently, somebody wrote it down for us, and we can read it with a clever Python import:

We’ll come back to this perspective later, but please keep this in mind: the perspective described here plays an important role in explaining how Python works, and why it works that way.

1. Python is easy.

Some people find Python easy. Others find it very challenging to learn. If you find Python challenging, Python’s reputation for being “easy” can make it feel like you shouldn’t program, because “even the easy language is too hard for you.” This is not true. Every programmer struggles to learn things sometimes.

This is why: humans made it up. All of it. You’ll recall that this means it’s inconsistent. Intuition often doesn’t work in computer science. The way you saw another programming language do something might explain, or might say absolutely nothing about, the way Python does it. At some point, almost every programmer runs into a concept, framework, or language that breaks their brain just because it is so different from what they have seen and used before. And that’s not just beginners; Dave Beazley teaches an Advanced Programming with Python class in which experienced Python programmers get their brains broken by Python.

You are not alone!

But here’s what people are getting at when they say Python is easy:

The perspective of the Python language values minimal syntax (“simple is better than complex”), a flat structure (“flat is better than nested”), and crucially, only one way to do something (“There should be one– and preferably only one –obvious way to do it”).

In designing a language, we face a tradeoff: expressiveness (how precisely we can communicate our intent through our code) versus interpretability (how easy it is to misinterpret what we said).

Ruby values expressiveness over interpretability: the artful Rubyist can construct code that reads more or less like an English sentence. Indeed, that was the intent of that language’s design. When this happens, it’s gorgeous to see. However, the inexperienced (or malevolent) Rubyist can construct code that works fine, but is utterly unintelligible.

Python values interpretability over expressiveness: the authors strive for there to be only one way to write something.

Here’s an example:

Python has no case statement. This makes it different from most major languages. This isn’t an oversight. Instead, the designers rejected the suggestion to add one. They felt that being able to make a stack of if...elif...elif... got the job done well enough.

So Python reads…kinda chunky, kinda clunky.

But because it’s lean on language constructs, there are fewer ways to misinterpret it. It’s harder to write illegible code. So you can get up and running faster with it than with other programming languages if computer science concepts or syntactic composition concepts are unfamiliar to you.

2. Python is a general-purpose programming language.

So, when we call Python “general purpose,” we’re taking “application development” as our frame of reference. There are all kinds of ways to give instructions to a computer that have nothing to do with application development.

Programmers have labeled these things—like CSS or HTML or SNOBOL or Alloy or TLA+ or Excel or SQL or Cypher or even APL (which, paradoxically, stands for “a programming language”)—as not programming languages, and therefore lesser tools, and their users lesser people, than programmers. Programmers use this artificial technical stratification to arbitrate who is more valuable/important than whom. When we fail to learn from the other disciplines that give instructions to computers, we deprive ourselves of all the lessons that we can learn from them to help us get better at the things that application development does badly.

Every tool works for specific jobs.

And we are responsible for knowing what that job is, so we don’t accidentally insinuate that that job is everything.

But here’s what people are getting at when they say Python is general purpose:

Python is useful for a lot of different things: data science, machine learning, web development, and systems level scripting, to name a few. It works on many different platforms like Linux, Windows, and MacOS—which cannot be said for, say, Swift, which just came to Windows in September of 2020.

Python also allows us to work in both imperative and functional paradigms, which is useful in situations where we might want each of these to solve different problems. Now, is it good at both? Not particularly. Plenty of other languages eclipse it here: Java, Swift, Kotlin, and Golang, to name a few. But it can do it, which affords some broader appeal that we don’t have with, for example, Clojure, Haskell, or C.

3. Python is Popular.

Python is popular, according to a few different indices that each measure a programming language’s popularity based on how many searches on various search engines contain their names.

It’s worth noting that a big chunk of Python searches happen because Python crossed over from a web app language to also get used in data science and machine learning capacities. Perl, Javascript, and PHP didn’t do that. So the Python traffic represented here is both web application development questions and data science questions.

Please keep in mind, as any good data scientist would, that “number of search engine hits,” which is what these indices measure, is a proxy metric for “How many people are actually using the language.” We don’t precisely know how good that proxy is.

But we don’t need this index to know that lots of companies are hiring programmers to write Python.

Here’s the part I want to question.

I think that the use of this reason often insinuates “If you know Python, you will always be able to get a job.” That’s not more true of Python than it is of most other popular programming languages. If you know Java, Ruby, or Javascript, you’ll also have opportunities. In fact, the hiring gap for programmers is so large right now that if you know any programming language, someone will probably interview you.

So that brings me to the bigger problem here: the fixed mindset around programming languages.

Within a given paradigm, most programming languages have a lot of similarities. And almost all popular programming languages use English keywords (I’m excluding a few collection manipulation languages that speak mostly in mathematical symbols). This means that, once you know one programming language, it’s usually easier for you to learn the second one than it was to learn the first one (note that I am saying easier, not easy ;). Your ramp-up time tends to get shorter and shorter with each successive language in a paradigm. So, knowing Python gives you the ability to do a Python job—but, with some weeks of study, so does knowing Ruby or JavaScript. There is one caveat here…

Data Science.

Now, here’s the thing about data science. To do data science, you have to know data science—that is, statistics, and usually a bunch of stuff about the specific domain you’re doing data science in. The main skill you need isn’t actually Python.

I have helped several researchers in the hard sciences write software to get their research done. None of them know Python, but they’ve all written their scripts in Python. It’s not great Python: they copied and pasted together stuff they found on StackOverflow.

But despite not knowing Python, they’re able to use a search engine to find the lines they need and get the job done with Python because they know data science.

In my experience, data science and machine learning code (in Python or another language) tends to leave a lot of speed and a lot of legibility on the table, but it gets the job done.

If your goal is to be a data scientist, I highly recommend taking statistics as well as classes in the particular field where you want to science data. Python is a nice-to-have, and I’d prefer you know Python if you’re doing data science, but from what I’ve seen in the real world, it’s not the most important skill a data scientist needs.

Fine, you grumpy curmudgeon.

If all these reasons have issues, why should I learn Python?

I’m so glad you asked!

The reason comes back to our earlier conversation about perspective.

Remember this?

This image has an empty alt attribute; its file name is Screen-Shot-2021-01-31-at-11.31.27-AM-1024x651.png

This poem was written as kind of a joke, and isn’t designed to be taken too seriously.

Nevertheless, the poem succinclty conveys the perspective that informed Python’s design.

It’s a useful perspective, and one that a lot of other programming language designers have borrowed from. And it’s a perspective that you, as a programmer, can borrow from, too.

What better way to learn to program than to do it with a language that leads by example with its simplicity, legibility, and practicality? Whether you’re writing Ruby, Java, Scala, Perl, or Klingon, these are valuable lessons to keep in mind. And they’ll make you a better programmer.

In any language.

If you liked this piece, you might also like:

The Advanced Programming with Python series

How to Jump-Start a New Programming Language, or maybe, even, gain a more concrete mental model of the one you already use!

Lessons from Space: Edge-Free Programming, which also explores an Android app’s design and the engineering choices behind it (plus, cool pictures of rockets!)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.