Join the 85,000 open source advocates who receive our giveaway alerts and article roundups.
Python is the best path for students
Bringing Python into the classroom
Get the newsletter
Teachers across the globe have answered the call to code. "Yes," they say, "we will teach our kids to program, even if we don't know how ourselves." They've delivered lessons on Scratch; they've celebrated the Hour of Code. Perhaps they've even dabbled in Codecademy's offerings to familiarize themselves with this newly popular, suddenly ubiquitous competency called "coding."
Where should students and teachers venture from there? Many—likely most—of these new explorers of computer programming are wholly unfamiliar with the language jungle that career developers and technologists swing through. This creates a stumbling point for students and teachers exploring computer science. Making the leap from visually assembling blocks of plain-language instructions as in Scratch to boldly typing bizarre syntax into a blank text editor is daunting to say the least. Tools like Codecademy can ease the transition, but even there the options can be overwhelming. After years of teaching students to program and think computationally, I'm convinced that Python is the best path after the usual learn-to-code activities. Here we'll explore how to get going in Python for authentic computer science discovery.
Consider the real goal of teaching programming. The Hour of Code puts it this way:
Every student should have the opportunity to learn computer science. It helps nurture problem-solving skills, logic and creativity. By starting early, students will have a foundation for success in any 21st-century career path.
I would add that the goal of coding for all, not just future scientists and engineers, is computational thinking: learning to analyze and classify problems, break hard problems down into smaller, simpler ones, and to modify and build tools suited to a given situation. Every student's future demands these skills.
Python is the clear choice for a first "real" programming language for young coders. Its clean syntax allows the concepts of computational thinking to take precedence over tricky language idiosyncrasies. Python is an interpreted language rather than a compiled one (like Java or C++), meaning revision and testing take less time. Python's wide library of modules like Turtle—an implementation of Logo-like drawing—make Python highly useable out-of-the-box. But perhaps most importantly, Python has serious momentum behind it: Python has overtaken Java as the most popular introductory programming language in top U.S. universities' computer science departments.
How best to get started? If you're on Linux, you already have everything you need to get started programming in Python. For Mac and Windows users, head on over to python.org to download the official IDLE interpreter/development environment. Until you and your students advance further in your Python journey, IDLE will be more than sufficient for your programming needs.
You might notice when you go to download Python that there seem to be two versions available: 2 and 3. Which should you choose? Python 2.7 is very stable but at the end of its development cycle. Python 3 is in active development and considered "current." Many also consider Python 3 to be a better teaching language. I'm among them.
With IDLE downloaded and installed, you and your students can begin exploring single-line commands. I'm a traditionalist, so I encourage you to begin with print("Hello, World!"). With that one line, your students will join the noble ranks of programmers.
Next up, variables are an easy intro. Try these commands:
>>> x = 5
>>> x + 2
And so on. It's crucial that students get comfortable with the idea of entering commands using the keyboard without much on-screen prompting. When they go to write their first .py file (Python's file extension), they'll be greeted with a blank screen and a blinking cursor. In time, this could come to represent the endless potential of programming, but at first they'll be adrift in a vast white pixel ocean.
You'll be tempted, if you are more familiar with Python than your students, to guide them through this period of confusion. A light touch is best here. Resist the temptation to spend most of your instructional time giving examples from the front of the classroom. Instead, let your students explore Python on their own—or even better, explore with them! Many teachers and students new to programming are hesitant to dive into the official documentation. In Python's case, the official documentation is clean and informative. When used in conjunction with a curriculum based around strong computer science fundamentals, the Python docs will become an invaluable resource. Moreover, teaching students how to research unknown pieces of a programming language is a worthy lesson itself. Any programmer worth their salt spends a good amount of their time researching what they don't already know.
Before long, you and your students will be importing modules into Python—random will most likely be the first. Perhaps you'll use turtle to create procedural art. Python comes with lots of helpful modules right from install, but soon I'm sue you and your students will want to do even more with Python. That's where pip comes in.
Pip, the Python Package Manager, allows users to install additional modules from the command line. Pip came with your download from python.org. With pip, and a dash of command line goodness, you can easily expand Python's capabilities.
One of the first modules I recommend installing with pip is matplotlib. Matplotlib is a venerable project that brings powerful data visualization to Python. With MPL, you can begin visually exploring data. If your students are taking algebra or higher math classes, there's profound potential for integrating Python into the math curriculum. Imagine having students make their own graphing calculator, or solving a probability problem using a Monte Carlo simulation.
Science, same thing. Simulations ranging from virus populations over time to flight trajectories of rockets are within easy reach with Python. When students have to build programs using mathematical or scientific concepts, their understanding of those concepts goes deeper than what's otherwise possible.
Here's a very simple math example: writing a function to find a square root. Sure, Python has a math.sqrt() function, but that takes all the fun out of it. Imagine you have no memorized math facts, but you know what a square root is and can do simple arithmetic. Now find the square root of 16. How do you go about it?
Puzzling through this problem in code serves two instructional goals: first, it ensures that students firmly understand the concept of roots and finding them. Second, since they will have to write some algorithm to hunt for the root, they will consider which of many possible strategies is most efficient. They will think computationally to solve a problem, and in doing so will have encountered and found a solution for an entire class of problems.
Once students have written a fair amount of code, you might seek a better method for collecting programming assignments. I recommend using git and an online repository like GitHub or BitBucket. GitHub is far more popular, and giving students a start making repos on GitHub might give them a professional edge. BitBucket has certain features attractive to educators, like free private repositories. Either way, learning to use git will be an important lesson for any young programmer. For teachers, these online code repositories can serve as distribution points for template code as well as a library of examples from others computer science teachers. CodeSchool has a great free intro to git and GitHub to get you started.
There's no shortage of further reading and resources for Python. Codecademy's Python track is rudimentary but worthwhile if this is your first programming language. Learn Python the Hard Way is a popular eBook/website that used to be all free and has since gone paid for the full version. I don't love Zed Shaw's scripting approach for complete beginners, although I see the benefit after students pick up the basics of Python. It's a minor investment for a great deal of content. But perhaps the richest, most valuable Python resources on the web right now are MIT's edX courses that use Python. MIT has provided hours of free instruction that delve into serious matters of computer science, but are approachable even for beginners. Although the courses take real effort to complete, the skills gained through the courses serve as a solid foundation for any new programmer.
Armed with these resources, you and your students are ready to begin exploring the world of code through the language of Python. As you take this journey, I would ask something of you: contribute your discoveries back to this community! If you develop successful lessons using Python (or any other programming language), consider releasing the code through GitHub or BitBucket so other teachers may benefit from your discoveries. This community of ours is strongest when everyone contributes. That might be the most important lesson of all for your students.
This article is part of the Back to School series focused on open source projects and tools for students of all levels.