1st Edition

A Functional Start to Computing with Python

By Ted Herman Copyright 2014
    429 Pages 52 B/W Illustrations
    by Chapman & Hall

    429 Pages
    by Chapman & Hall

    A Functional Start to Computing with Python enables students to quickly learn computing without having to use loops, variables, and object abstractions at the start. Requiring no prior programming experience, the book draws on Python’s flexible data types and operations as well as its capacity for defining new functions. Along with the specifics of Python, the text covers important concepts of computing, including software engineering motivation, algorithms behind syntax rules, advanced functional programming ideas, and, briefly, finite state machines.

    Taking a student-friendly, interactive approach to teach computing, the book addresses more difficult concepts and abstractions later in the text. The author presents ample explanations of data types, operators, and expressions. He also describes comprehensions—the powerful specifications of lists and dictionaries—before introducing loops and variables. This approach helps students better understand assignment syntax and iteration by giving them a mental model of sophisticated data first.

    Web Resource
    The book’s supplementary website at http://functionalfirstpython.com/ provides many ancillaries, including:

    • Interactive flashcards on Python language elements
    • Links to extra support for each chapter
    • Unit testing and programming exercises
    • An interactive Python stepper tool
    • Chapter-by-chapter points
    • Material for lectures

    Motivation and Background
    Inspirations of Computing

    Preview of Computing with Python
    Spiral Drawing
    Reports
    Goal

    General Landscape of Computing Languages
    Background Skills
    Learning a Language

    Python Setup
    Distributions
    Dialects
    Calculator Mode
    Running a Script
    Microsoft Windows
    Integrated Development Environments (IDEs)
    Web Browsers

    Functional-Style Python
    Types
    It’s All 0 and 1
    Programming Language Types
    Primitives: Numbers, Characters, Booleans
    Sequences: Tuples, Lists, Strings, Dictionaries
    Type Queries
    Yet More Types

    Operators
    Numeric: Float and Integer Arithmetic
    Integer Operators
    Comparison: Numeric, General, and Type
    General Comparison
    Type Comparison
    Boolean Operators: And, Or, Not
    Sequence Operators: Concatenation and Containment
    Hidden Operators: Function Application, Indexing, Lookup
    Method Calls

    Expressions
    Sequential Reduction
    Well-Formed Expressions
    Parentheses and Priorities
    Rules of Evaluation
    Names for Values

    Printing
    Basic Print
    String Trivia

    Functions I
    Function Syntax
    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

    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

    Imperative-Style Python
    Names for Data
    Constants
    Variables
    Assignment Syntax
    List and Dictionary Item Assignment
    Deleting Variables and Items
    Where Assignment Goes

    Functions and Variables
    Scope of Variables
    Variables in Functions
    Local and Global Scope
    Default Global

    Mutation
    Mutation and Assignment
    Slice Assignment
    Mutation in Functions
    Aliases
    Mutation and Augmented Assignment
    Items as References

    Modules
    Import Statements
    Selective Import
    Name Spaces
    Name Queries
    Module Help
    Python Standard Library
    Module Placement
    Learning More
    The World of Packages
    Treasure

    Repetition
    Repeating Statements
    For-Loops with Variables
    For-Loops with Variables
    Loops on Condition: While Statements
    Feedback Control
    Recursion

    Documentation
    Comments in Programs
    Motivations for Documentation
    Cruft, Clarity, and Style
    The Pass Statement
    Pseudocode

    Debugging
    Kinds of Bugs
    Methods of Debugging
    Assertions and Testing

    Accumulation Loop Patterns
    Block Repetition
    The Accumulation Pattern
    Going Further

    Search Loop Patterns
    Sequential Search
    Altering Control Flow: Break and Continue
    Nested Loops
    Recursive Data

    Drawing
    Turtle Drawing
    Drawing by Shapes
    Graphing Data

    Input and Output
    Console and Keyboard Input
    Output Formatting
    Reading Files
    Writing to Files

    Network Programs
    Reading a Web Page
    The Try and Except Statements
    Catching Errors
    Catching Network Errors
    Making a Web Server
    Client and Server

    Objects, Classes, and Inheritance
    Classes, Instances, Objects, Attributes
    Methods Are Functions
    The Init Method
    Subclasses
    Period Syntax
    Example: Date/Time Objects
    Example: Regular Expressions
    Example: HTML 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

    Appendices
    Advanced Topics
    Decorators
    Python Magic
    Platforms and Virtual Machines
    Scripts as Commands
    Trivia

    Solutions to *-Exercises

    Reference Tables

    Index

    Terminology Review and Exercises appear at the end of each chapter.

    Biography

    Ted Herman