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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access