Figure slides available with qualifying course adoption
Open source and easy to use, Python offers the availability of exciting libraries of software, application programming interfaces, and even connections to web services. This textbook uses Python as a working environment to teach the basics of computing for students with no prior programming experience. Unlike similar texts, it organizes topics based on a functional first approach to teaching programming. The book includes case studies of practical problems as well as homework and interactive tools online, such as flashcards.
I Motivation and Background
Inspirations of Computing
Preview of Computing with Python
General Landscape of Computing Languages
Python Setup
II Functional-Style Python
Types
Primitives: Numbers, Characters, Booleans
Sequences: Tuples, Lists, Strings, Dictionaries
Putting Types Together
Type Queries
Yet More Types
Interlude: An Inventory Problem
Operators
Numeric: Float and Integer Arithmetic
Comparison: Numeric, General, and Type
Boolean Operators: And, Or, Not
Sequence Operators: Concatenation and Containment
Hidden Operators: Function Application, Indexing, Lookup
Method Calls
Expressions
Sequential Reduction
Parentheses and Priorities
Rules of Evaluation
Names for Values
Interlude: Puzzles with Expressions
Printing
Basic Print
Print as Function (Python3) or Print as Command (Python2)
String Interpretation
String Trivia
Functions I
Function Syntax
One-Line Functions: Lambdas
Multiline Functions: The Def Command
Head, Body, Parameters and Arguments
Functions as Commands
Functions II
Parameters: Binding by Position
Arguments by Keyword
Default Parameters by Keyword
Return and None
Using Function Calls and Names
Python’s Built-in Functions
Type Conversion
Namespace Queries
Function Composition
Local Functions
Interlude: Table Lookup Functions
Exercises: Unit Testing and Online Supplement
Conditional Logic
Control Flow Using If
Nested If
Levels and Statement Blocks
Else and Elif
Example: Reacting to Type Comparison
Slice, Split, Join
Slices of Sequences, Slices Are Sequences
Splitting Strings
Strings to Words
Joining Lists of Strings
Other Handy String Methods
Method on Method
Comprehensions
List Functions: max, min, sum, zip, all, any
List Functions: filter, map, reduce
Streams, Generators, and Iterators
Range Function/Generator
List Comprehensions
Python Generators
Dictionary Comprehensions
Multiline Expressions
Functional Patterns
Tail Recursion
Comprehension Patterns
Creating Structures
Searching and Filtering
Operator, Functools, Itertools
Trees
Regular Expressions
Case Study: Tic-Tac-Toe
III Imperative-Style Python
Names for Data
Constants
Variables
Assignment Syntax
List and Dictionary Item Assignment
Deleting Variables and Items
Functions and Variables
Scope of Variables
Variables in Functions
Local and Global Scope
Mutation
Mutation and Assignment
Slice Assignment
Mutation in Functions
Aliases
Mutation and Augmented Assignment
Items as References
Modules
Import Statements
Selective Import
Name Spaces
Module Help
Python Standard Library
The World of Packages
Repetition for-Loops with Variables
Loops on Condition: While Statements
Feedback Control
Recursion
Interlude: Game Cycle
Documentation
Comments in Programs
Motivations for Documentation
Cruft, Clarity, and Style
Pseudocode
Debugging
Kinds of Bugs
Methods of Debugging
Assertions and Testing
Accumulation Loop Patterns
Block Repetition
The Accumulation Pattern
Search Loop Patterns
Break and Continue
Nested Loops
Recursive Data
Drawing
Turtle Drawing
Drawing by Shapes
Graphing Data
Interlude: Animation Design
Input and Output
Console and Keyboard Input
Input Conversion and Validation
Output Formatting
Reading Files
Reading Lines and Bytes
Standard Input and Standard Output
Writing to Files
Interlude: File Indexing
Network Programs
Reading a Webpage
The Try and Except Statements
Catching Network Errors
Making a Webserver
Client and Server
Objects, Classes and Inheritance
Classes, Instances, Objects, Attributes
Methods are Functions
The Init Method
Subclasses
Example: Date/Time Objects
Example: Regular Expressions
Example: HTML Processing
Interlude: Signal Processing
Randomness, Time, and System Modules
The Random Module
The Time Module
The Sys Module
The OS Module
Graphical User Interfaces
GUI Concepts: Widgets, Layout, Actions
Programming with a GUI Framework
The Tk GUI
Frame and Label
Buttons
IV Appendices
Advanced Topics
Decorators
Python Magic
Platforms and Virtual Machines
Scripts as Commands
Solutions to P-Exercises
Reference Tables