Python For Programmers
Python For Programmers
Introduction to Computers
and Python
Objectives
In this chapter you’ll:
■ Learn about exciting recent developments in computing.
Outline
1.1 Introduction 1.6 The Cloud and the Internet of Things
1.2 A Quick Review of Object 1.6.1 The Cloud
1.6.2 Internet of Things
Technology Basics
1.7 How Big Is Big Data?
1.3 Python 1.7.1 Big Data Analytics
1.4 It’s the Libraries! 1.7.2 Data Science and Big Data Are Making
1.4.1 Python Standard Library a Difference: Use Cases
1.4.2 Data-Science Libraries 1.8 Case Study—A Big-Data Mobile
1.5 Test-Drives: Using IPython and Application
Jupyter Notebooks 1.9 Intro to Data Science: Artificial
1.5.1 Using IPython Interactive Mode as a Intelligence—at the Intersection of
Calculator
1.5.2 Executing a Python Program Using CS and Data Science
the IPython Interpreter 1.10 Wrap-Up
1.5.3 Writing and Executing Code in a
Jupyter Notebook
1.1 Introduction
Welcome to Python—one of the world’s most widely used computer programming lan-
guages and, according to the Popularity of Programming Languages (PYPL) Index, the
world’s most popular.1
Here, we introduce terminology and concepts that lay the groundwork for the Python
programming you’ll learn in Chapters 2–10 and the big-data, artificial-intelligence and
cloud-based case studies we present in Chapters 11–16.
We’ll review object-oriented programming terminology and concepts. You’ll learn why
Python has become so popular. We’ll introduce the Python Standard Library and various
data-science libraries that help you avoid “reinventing the wheel.” You’ll use these libraries
to create software objects that you’ll interact with to perform significant tasks with modest
numbers of instructions.
Next, you’ll work through three test-drives showing how to execute Python code:
• In the first, you’ll use IPython to execute Python instructions interactively and
immediately see their results.
• In the second, you’ll execute a substantial Python application that will display an
animated bar chart summarizing rolls of a six-sided die as they occur. You’ll see
the “Law of Large Numbers” in action. In Chapter 6, you’ll build this application
with the Matplotlib visualization library.
• In the last, we’ll introduce Jupyter Notebooks using JupyterLab—an interactive,
web-browser-based tool in which you can conveniently write and execute Python
instructions. Jupyter Notebooks enable you to include text, images, audios, vid-
eos, animations and code.
In the past, most computer applications ran on standalone computers (that is, not net-
worked together). Today’s applications can be written with the aim of communicating
among the world’s billions of computers via the Internet. We’ll introduce the Cloud and
the Internet of Things (IoT), laying the groundwork for the contemporary applications
you’ll develop in Chapters 11–16.
You’ll learn just how big “big data” is and how quickly it’s getting even bigger. Next,
we’ll present a big-data case study on the Waze mobile navigation app, which uses many
current technologies to provide dynamic driving directions that get you to your destina-
tion as quickly and as safely as possible. As we walk through those technologies, we’ll men-
tion where you’ll use many of them in this book. The chapter closes with our first Intro to
Data Science section in which we discuss a key intersection between computer science and
data science—artificial intelligence.
Automobile as an Object
To help you understand objects and their contents, let’s begin with a simple analogy. Sup-
pose you want to drive a car and make it go faster by pressing its accelerator pedal. What must
happen before you can do this? Well, before you can drive a car, someone has to design it.
A car typically begins as engineering drawings, similar to the blueprints that describe the
design of a house. These drawings include the design for an accelerator pedal. The pedal
hides from the driver the complex mechanisms that make the car go faster, just as the brake
pedal “hides” the mechanisms that slow the car, and the steering wheel “hides” the mech-
anisms that turn the car. This enables people with little or no knowledge of how engines,
braking and steering mechanisms work to drive a car easily.
Just as you cannot cook meals in the blueprint of a kitchen, you cannot drive a car’s
engineering drawings. Before you can drive a car, it must be built from the engineering
drawings that describe it. A completed car has an actual accelerator pedal to make it go
faster, but even that’s not enough—the car won’t accelerate on its own (hopefully!), so the
driver must press the pedal to accelerate the car.
deposit money to an account, another to withdraw money from an account and a third to
inquire what the account’s balance is. A class is similar in concept to a car’s engineering
drawings, which house the design of an accelerator pedal, steering wheel, and so on.
Instantiation
Just as someone has to build a car from its engineering drawings before you can drive a car,
you must build an object of a class before a program can perform the tasks that the class’s
methods define. The process of doing this is called instantiation. An object is then referred
to as an instance of its class.
Reuse
Just as a car’s engineering drawings can be reused many times to build many cars, you can
reuse a class many times to build many objects. Reuse of existing classes when building new
classes and programs saves time and effort. Reuse also helps you build more reliable and
effective systems because existing classes and components often have undergone extensive
testing, debugging and performance tuning. Just as the notion of interchangeable parts was
crucial to the Industrial Revolution, reusable classes are crucial to the software revolution
that has been spurred by object technology.
In Python, you’ll typically use a building-block approach to create your programs. To
avoid reinventing the wheel, you’ll use existing high-quality pieces wherever possible. This
software reuse is a key benefit of object-oriented programming.
Inheritance
A new class of objects can be created conveniently by inheritance—the new class (called
the subclass) starts with the characteristics of an existing class (called the superclass), pos-
sibly customizing them and adding unique characteristics of its own. In our car analogy,
an object of class “convertible” certainly is an object of the more general class “automo-
bile,” but more specifically, the roof can be raised or lowered.
1.3 Python
Python is an object-oriented scripting language that was released publicly in 1991. It was
developed by Guido van Rossum of the National Research Institute for Mathematics and
Computer Science in Amsterdam.
Python has rapidly become one of the world’s most popular programming languages.
It’s now particularly popular for educational and scientific computing,2 and it recently
surpassed the programming language R as the most popular data-science programming
language.3,4,5 Here are some reasons why Python is popular and everyone should consider
learning it:6,7,8
• It’s open source, free and widely available with a massive open-source community.
• It’s easier to learn than languages like C, C++, C# and Java, enabling novices and
professional developers to get up to speed quickly.
2. [Link]
3. [Link]
[Link].
4. [Link]
leaves-them-both-behind/.
5. [Link]
6. [Link]
7. [Link]
8. [Link]