Table of Contents

1. Introduction to Python 2

1.1 Programming (general)
1.2 Programming using Python
1.3 Basic input and output
1.4 Errors
1.5 Development environment
1.6 Computers and programs (general)
1.7 Computer tour
1.8 Language history
1.9 Python example: Salary calculation
1.10 Additional practice: Output art

2. Variables and Expressions

2.1 Variables and assignments
2.2 Identifiers
2.3 Objects
2.4 Numeric types: Floating-point
2.5 Arithmetic expressions
2.6 Python expressions
2.7 Division and modulo
2.8 Module basics
2.9 Math module
2.10 Representing text
2.11 Additional practice: Number games

3. Types

3.1 String basics
3.2 Lists basics
3.3 Set basics
3.4 Dictionary basics
3.5 Common data types summary
3.6 Additional practice: Grade calculation
3.7 Type conversions
3.8 String formatting
3.9 Binary numbers
3.10 Additional practice: Health data

4. Branching

4.1 If-else branches (general)
4.2 If-else statement
4.3 More if-else
4.4 Equality and relational operators
4.5 Boolean operators and expressions
4.7 Order of evaluation
4.6 Membership and identity operators
4.8 Code blocks and indentation
4.9 Conditional expressions
4.10 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
8.16 String formatting using dictionaries

9. Classes

9.1 Classes: Introduction
9.2 Classes: Grouping data
9.3 Instance 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
9.10 Memory allocation and garbage collection

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

16. Searching and Sorting Algorithms

16.1 Searching and algorithms
16.2 Binary search
16.3 O notation
16.4 Algorithm analysis
16.5 Sorting: Introduction
16.6 Selection sort
16.7 Insertion sort
16.8 Quicksort
16.9 Merge sort

17. Additional Material

17.1 zyBooks built-in programming window

What You’ll Find In This zyBook:

More action with less text.

  • ~600 participation activities: Questions, animations, tools
  • ~100 auto-graded programming challenge activities using built-in programming environment
  • Configurable for high schools and non-majors

Instructors: Interested in evaluating this zyBook for your class? Sign up for a Free Trial and check out the first chapter of any zyBook today!

The zyBooks Approach

Less text doesn’t mean less learning.

Provides interactive learning of programming foundations and C. Emphasizes a solid understanding of memory. From the moment variables are introduced, the material shows via animations how variables exist and are updated in memory. The continued showing of memory throughout helps clarify challenging topics like pass-by-copy/pointer parameters, arrays, pointers, and more. Furthermore, the material includes emphasis on disciplined program development, including incremental development, modular development, and testing/debugging.

This zyBook can also be mix-and-matched with others, such as with Data Structures Essentials (a popular combination).

“The most striking aspect of ZyBooks for me as an instructor has been the ability to introduce a topic and then point my students to specific exercises/activities in ZyBooks that would not only expound on the concept but allow them to practice them with confidence.”

Ramesh YerraballiSenior Lecturer Dept. of Electrical & Comp Engrs, UT Austin

Author

Bailey Miller
CSE Ph.D., Univ. of California, Riverside
zyBooks (Former software engineer at SpaceX)

Combine Programming In Python 2 With These Other zyBooks

Programming In Python 2 is often combined with other zyBooks to give students experience with a diverse set of programming languages. Some popular titles to pair with Programming In Python 2 include: