You are previewing Introduction to Programming in Python: An Interdisciplinary Approach.
O'Reilly logo
Introduction to Programming in Python: An Interdisciplinary Approach

Book Description

Today, anyone in a scientific or technical discipline needs programming skills. Python is an ideal first programming language, and Introduction to Programming in Python is the best guide to learning it.

Princeton University’s Robert Sedgewick, Kevin Wayne, and Robert Dondero have crafted an accessible, interdisciplinary introduction to programming in Python that emphasizes important and engaging applications, not toy problems. The authors supply the tools needed for students to learn that programming is a natural, satisfying, and creative experience.

This example-driven guide focuses on Python’s most useful features and brings programming to life for every student in the sciences, engineering, and computer science.

Coverage includes

  • Basic elements of programming: variables, assignment statements, built-in data types, conditionals, loops, arrays, and I/O, including graphics and sound

  • Functions, modules, and libraries: organizing programs into components that can be independently debugged, maintained, and reused

  • Object-oriented programming and data abstraction: objects, modularity, encapsulation, and more

  • Algorithms and data structures: sort/search algorithms, stacks, queues, and symbol tables

  • Examples from applied math, physics, chemistry, biology, and computer science—all compatible with Python 2 and 3

  • Drawing on their extensive classroom experience, the authors provide Q&As, exercises, and opportunities for creative practice throughout. An extensive amount of supplementary information is available at introcs.cs.princeton.edu/python. With source code, I/O libraries, solutions to selected exercises, and much more, this companion website empowers people to use their own computers to teach and learn the material.

    Table of Contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Contents
    6. Programs
    7. Preface
      1. Coverage
      2. Use in the Curriculum
      3. Prerequisites
      4. Goals
      5. Booksite
      6. Acknowledgments
    8. Chapter One. Elements of Programming
      1. 1.1 Your First Program
        1. Programming in Python
        2. Input and output
      2. Q&A
      3. Exercises
      4. 1.2 Built-in Types of Data
        1. Definitions
        2. Strings
        3. Integers
        4. Floating-point numbers
        5. Booleans
        6. Comparisons
        7. Functions and APIs
        8. Type conversion
        9. Summary
      5. Q&A (strings)
      6. Q&A (integers)
      7. Q&A (floating-point numbers)
      8. Q&A
      9. Exercises
      10. Creative Exercises
      11. 1.3 Conditionals and Loops
        1. If statements
        2. Else clauses
        3. While statements
        4. For statements
        5. Nesting
        6. Applications
        7. Loop and a half
        8. Infinite loops
        9. Summary
      12. Q&A
      13. Exercises
      14. Creative Exercises
      15. 1.4 Arrays
        1. Arrays in Python
        2. Array aliases and copies
        3. System support for arrays
        4. Sample applications of arrays
        5. Coupon collector
        6. Sieve of Eratosthenes
        7. Two-dimensional arrays
        8. Example: self-avoiding random walks
        9. Summary
      16. Q&A
      17. Exercises
      18. Creative Exercises
      19. 1.5 Input and Output
        1. Bird’s-eye view
        2. Standard output
        3. Standard input
        4. Redirection and piping
        5. Standard drawing
        6. Animation
        7. Standard audio
        8. Summary
      20. Q&A
      21. Exercises
      22. Creative Exercises
      23. 1.6 Case Study: Random Web Surfer
        1. Input format
        2. Transition matrix
        3. Simulation
        4. Mixing a Markov chain
        5. Lessons
      24. Exercises
      25. Creative Exercises
    9. Chapter Two. Functions and Modules
      1. 2.1 Defining Functions
        1. Using and defining functions
        2. Implementing mathematical functions
        3. Using functions to organize code
        4. Passing arguments and returning values
        5. Example: superposition of sound waves
      2. Q&A
      3. Exercises
      4. Creative Exercises
      5. 2.2 Modules and Clients
        1. Using functions in other programs
        2. Modular programming abstractions
        3. Random numbers
        4. Array-processing API
        5. Iterated function systems
        6. Standard statistics
        7. Modular programming
      6. Q&A
      7. Exercises
      8. Creative Exercises
      9. 2.3 Recursion
        1. Your first recursive program
        2. Mathematical induction
        3. Euclid’s algorithm
        4. Towers of Hanoi
        5. Function-call trees
        6. Exponential time
        7. Gray codes
        8. Recursive graphics
        9. Brownian bridge
        10. Pitfalls of recursion
        11. Perspective
      10. Q&A
      11. Exercises
      12. Creative Exercises
      13. 2.4 Case Study: Percolation
        1. Percolation
        2. Basic scaffolding
        3. Vertical percolation
        4. Testing
        5. Estimating probabilities
        6. Recursive solution for percolation
        7. Adaptive plot
        8. Lessons
      14. Q&A
      15. Exercises
      16. Creative Exercises
    10. Chapter Three. Object-Oriented Programming
      1. 3.1 Using Data Types
        1. Methods
        2. String processing
        3. String-processing application: genomics
        4. A user-defined data type
        5. Color
        6. Digital image processing
        7. Input and output revisited
        8. Memory management
      2. Q&A
      3. Exercises
      4. Creative Exercises
      5. 3.2 Creating Data Types
        1. Basic elements of a data type
        2. Stopwatch
        3. Histogram
        4. Turtle graphics
        5. Complex numbers
        6. Mandelbrot set
        7. Commercial data processing
      6. Q&A
      7. Exercises
      8. Creative Exercises
      9. 3.3 Designing Data Types
        1. Designing APIs
        2. Encapsulation
        3. Immutability
        4. Example: spatial vectors
        5. Tuples
        6. Polymorphism
        7. Overloading
        8. Functions are objects
        9. Inheritance
        10. Application: data mining
        11. Design-by-contract
      10. Q&A
      11. Exercises
      12. Data-Type Design Exercises
      13. Creative Exercises
      14. 3.4 Case Study: N-Body Simulation
        1. N-body simulation
      15. Q&A
      16. Exercises
      17. Creative Exercises
    11. Chapter Four. Algorithms and Data Structures
      1. 4.1 Performance
        1. Scientific method
        2. Observations
        3. Hypotheses
        4. Order of growth classifications
        5. Predictions
        6. Caveats
        7. Performance guarantees
        8. Python lists and arrays
        9. Strings
        10. Memory
        11. Perspective
      2. Q&A
      3. Exercises
      4. Creative Exercises
      5. 4.2 Sorting and Searching
        1. Binary search
        2. Insertion sort
        3. Mergesort
        4. Python system sort
        5. Application: frequency counts
        6. Lessons
      6. Q&A
      7. Exercises
      8. Creative Exercises
      9. 4.3 Stacks and Queues
        1. Pushdown stacks
        2. Python list (resizing array) implementation of a stack
        3. Linked-list implementation of a stack
        4. Stack applications
        5. FIFO queues
        6. Queue applications
        7. Resource allocation
      10. Q&A
      11. Exercises
      12. Linked-List Exercises
      13. Creative Exercises
      14. 4.4 Symbol Tables
        1. API
        2. Symbol table clients
        3. Elementary symbol-table implementations
        4. Hash tables
        5. Binary search trees
        6. Performance characteristics of BSTs
        7. Traversing a BST
        8. Iterables
        9. Ordered symbol table operations
        10. Dictionary data type
        11. Set data type
        12. Perspective
      15. Q&A
      16. Exercises
      17. Binary Tree Exercises
      18. Creative Exercises
      19. 4.5 Case Study: Small-World Phenomenon
        1. Graphs
        2. Graph data type
        3. Graph client example
        4. Shortest paths in graphs
        5. Small-world graphs
        6. Lessons
      20. Q&A
      21. Exercises
      22. Creative Exercises
    12. Context
      1. Standard Python modules
      2. Programming environments
      3. Scientific computing
      4. Computer systems
      5. Theoretical computer science
    13. Glossary
    14. Index
    15. APIs
    16. Code Snippets