Contents

Preface

1 Python Primer

1.1 Python Overview

1.1.1 The Python Interpreter

1.1.2 Preview of a Python Program

1.2 Objects in Python

1.2.1 Identifiers, Objects, and the Assignment Statement

1.2.2 Creating and Using Objects

1.2.3 Python's Built-In Classes

1.3 Expressions, Operators, and Precedence

1.3.1 Compound Expressions and Operator Precedence

1.4 Control Flow

1.4.1 Conditionals

1.4.2 Loops

1.5 Functions

1.5.1 Information Passing

1.5.2 Python's Built-In Functions

1.6 Simple Input and Output

1.6.1 Console Input and Output

1.6.2 Files

1.7 Exception Handling

1.7.1 Raising an Exception

1.7.2 Catching an Exception

1.8 Iterators and Generators

1.9 Additional Python Conveniences

1.9.1 Conditional Expressions

1.9.2 Comprehension Syntax

1.9.3 Packing and Unpacking of Sequences

1.10 Scopes and Namespaces

1.11 Modules and the Import Statement

1.11.1 Existing Modules

1.12 Exercises

2 Object-Oriented Programming

2.1 Goals, Principles, and Patterns

2.1.1 Object-Oriented Design Goals

2.1.2 Object-Oriented Design Principles

2.1.3 Design Patterns

2.2 Software Development

2.2.1 Design

2.2.2 Pseudo-Code

2.2.3 Coding Style and Documentation

2.2.4 Testing and Debugging

2.3 Class Definitions

2.3.1 Example: CreditCard Class

2.3.2 Operator Overloading and Python's Special Methods

2.3.3 Example: Multidimensional Vector Class

2.3.4 Iterators

2.3.5 Example: Range Class

2.4 Inheritance

2.4.1 Extending the CreditCard Class

2.4.2 Hierarchy of Numeric Progressions

2.4.3 Abstract Base Classes

2.5 Namespaces ...

Get Data Structures and Algorithms in Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.