Programming in Python 2
Bailey Miller
zyBooks 2017

Table of Contents

1. Introduction to Python 2.x
1.1 Programming introduction
1.2 Computational thinking
1.3 The Python interactive interpreter
1.4 Programming in Python
1.5 Basic output
1.6 Basic input
1.7 Errors
1.8 Additional practice: Output art
1.9 Development environment
1.10 Computers and programs
1.11 Computer tour
1.12 Language history

2. Variables and Expressions
2.1 Objects and variables
2.2 Assignments
2.3 More on objects
2.4 Names
2.5 Numeric types: Floating-point
2.6 Expressions
2.7 Module basics
2.8 Math module
2.9 Additional practice: Number games
2.10 Representing text

3. Types
3.1 String basics
3.2 Lists basics
3.3 Dictionary basics
3.4 Common data types summary
3.5 Additional practice: Grade calculation
3.6 Type conversions
3.7 String formatting
3.8 Numbers in binary
3.9 Additional practice: Health data

4. Branching
4.1 If-else statement
4.2 Relational and equality operators
4.3 Multiple if-else
4.4 Boolean operators and expressions
4.5 Membership operators
4.6 Code blocks and indentation
4.7 Conditional expressions
4.8 Additional practice: Tweet decoder

5. Loops
5.1 Loops
5.2 While loops
5.3 More while examples
5.4 Counting
5.5 For loops
5.6 Counting using the range() function
5.7 While vs. for loops
5.8 Nested loops
5.9 Developing programs incrementally
5.10 Break and continue
5.11 Loop else
5.12 Getting both index and value when looping: enumerate()
5.13 Additional practice: Dice statistics

6. Functions
6.1 User-defined function basics
6.2 Function parameters
6.3 Returning values from functions
6.4 Dynamic typing
6.5 Reasons for defining functions
6.6 Function with branches/loops
6.7 Function stubs
6.8 Functions are objects
6.9 Functions: Common errors
6.10 Scope of variables and functions
6.11 Namespaces and scope resolution
6.12 Function arguments
6.13 Keyword arguments and default parameter values
6.14 Arbitrary argument lists
6.15 Multiple function outputs
6.16 Help! Using docstrings to document functions
6.17 Engineering examples

7. Strings
7.1 String slicing
7.2 Advanced string formatting
7.3 String methods
7.4 Splitting and joining strings
7.5 The string format method

8. Lists and Dictionaries
8.1 Lists
8.2 List methods
8.3 Iterating over a list
8.4 List games
8.5 List nesting
8.6 List slicing
8.7 Loops modifying lists
8.8 List comprehensions
8.9 Sorting lists
8.10 Command-line arguments
8.11 Additional practice: Engineering examples
8.12 Dictionaries
8.13 Dictionary methods
8.14 Iterating over a dictionary
8.15 Dictionary nesting

9. Classes
9.1 Classes: Introduction
9.2 Classes: Grouping data
9.3 Class methods
9.4 Class and instance object types
9.5 Class examples
9.6 Class constructors
9.7 Class interfaces
9.8 Class customization
9.9 More operator overloading: Classes as numeric types

10. Exceptions
10.1 Handling exceptions using try and except
10.2 Multiple exception handlers
10.3 Raising exceptions
10.4 Exceptions with functions
10.5 Using finally to cleanup
10.6 Custom exception types

11. Modules
11.1 Modules
11.2 Finding modules
11.3 Importing specific names from a module
11.4 Executing modules as scripts
11.5 Reloading modules
11.6 Packages
11.7 Standard library

12. Files
12.1 Reading files
12.2 Writing files
12.3 Interacting with file systems
12.4 Binary data
12.5 Command-line arguments and files
12.6 The ‘with’ statement
12.7 Comma separated values files

13. Inheritance
13.1 Derived classes
13.2 Accessing base class attributes
13.3 Overriding class methods
13.4 New vs. old-style classes
13.5 Is-a versus has-a relationships
13.6 Mixin classes and multiple inheritance
13.7 Testing your code: The unittest module

14. Recursion
14.1 Recursive functions
14.2 Recursive algorithm: Search
14.3 Adding output statements for debugging
14.4 Creating a recursive function
14.5 Recursive math functions
14.6 Recursive exploration of all possibilities

15. Plotting
15.1 Introduction to plotting and visualizing data
15.2 Styling plots
15.3 Text and annotations
15.4 Numpy
15.5 Multiple plots