O'Reilly logo

Python in Education by Nicholas H. Tollervey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Why Python in Education?

I am going to answer a very simple question: which features of the Python language itself make it appropriate for education? This will involve learning a little Python and reading some code. But don’t worry if you’re not a coder! This chapter will hopefully open your eyes to how easy it is to learn Python (and thus, why it is such a popular choice as a teaching language).

Code Readability

When I write a to-do list on a piece of paper, it looks something like this:

Shopping
Fix broken gutter
Mow the lawn  

This is an obvious list of items. If I wanted to break down my to-do list a bit further, I might write something like this:

Shopping:
    Eggs
    Bacon
    Tomatoes
Fix broken gutter:
    Borrow ladder from next door
    Find hammer and nails
    Return ladder!
Mow the lawn:
    Check lawn around pond for frogs
    Check mower fuel level 

Intuitively we understand that the main tasks are broken down into sub-tasks that are indented underneath the main task to which they relate. This makes it easy to see, at a glance, how the tasks relate to each other.

This is called scoping.

Indenting in this manner is also how Python organizes the various tasks defined in Python programs. For example, the following code simply says that there is a function called say_hello that asks the user to input their name, and then—you guessed it—prints a friendly greeting:

def say_hello():
    name = input('What is your name? ')
    print('Hello, ' + name)

Here’s this code in action (including my user ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required