Category: Python

Text Processing in Python

  • Author: David Mertz
  • Format: plain text
  • Price: free

Text Processing in Python describes techniques for manipulation of text using the Python programming language. At the broadest level, text processing is simply taking textual information and doing something with it. This might be restructuring or reformatting it, extracting smaller bits of information from it, or performing calculations that depend on the text. Text processing is arguably what most programmers spend most of their time doing.

Because Python is clear, expressive, and object-oriented it is a perfect language for doing text processing, even better than Perl. As the amount of data everywhere continues to increase, this is more and more of a challenge for programmers.

This book is not a tutorial on Python. It has two other goals: helping the programmer get the job done pragmatically and efficiently; and giving the reader an understanding – both theoretically and conceptually – of why what works works and what doesn’t work doesn’t work. Mertz provides practical pointers and tips that emphasize efficient, flexible, and maintainable approaches to the text processing tasks that working programmers face daily.

Continue reading

Introduction to Programming using Python

  • Author: Katja Schuerer, Corinne Maufrais, Catherine Letondal, Eric Deveaud, Marie-Agnes Petit
  • Format: PDF
  • Price: free

The objective of this course is to teach programming concepts to biologists. It is thus aimed at people who are not professional computer scientists, but who need a better control of computers for their own research.

Continue reading

Think Python: How to Think Like a Computer Scientist

  • Author: Allen B. Downey
  • Format: online HTML, PDF
  • Price: free

Think Python is an introduction to Python programming for beginners. It starts with basic concepts of programming, and is carefully designed to define all terms when they are first used and to develop each new concept in a logical progression. Larger pieces, like recursion and object-oriented programming are divided into a sequence of smaller steps and introduced over the course of several chapters.

Some examples and exercises are based on Swampy, a Python package written by the author to demonstrate aspects of software design, and to give readers a chance to experiment with simple graphics and animation.

Continue reading

Dive Into Python 3

My image
  • Author: Mark Pilgrim
  • Format: PDF, online HTML, archived HTML
  • Price: free

Dive Into Python 3 covers Python 3 and its differences from Python 2. Compared to Dive Into Python, it’s about 20% revised and 80% new material.

Chapters include:

  • What’s New in “Dive Into Python 3”
  • Installing Python
  • Your First Python Program
  • Native Datatypes
  • Comprehensions
  • Strings
  • Regular Expressions
  • Closures & Generators
  • Classes & Iterators
  • Advanced Iterators
  • Unit Testing
  • Refactoring
  • Files
  • XML
  • Serializing Python Objects
  • HTTP Web Services
  • Case Study: Porting chardet to Python 3
  • Packaging Python Libraries
  • Porting Code to Python 3 with 2to3
  • Special Method Names
  • Where to Go From Here
  • Troubleshooting

Dive Into Python

  • Author: Mark Pilgrim
  • Format: archived PDF, online HTML, archived HTML, Word 97 DOC, plain text, XML
  • Price: free

Dive Into Python is a free Python book for experienced programmers, published under the GNU Free Documentation License, which gives you enormous freedoms to modify and redistribute it in all its forms..

It was originally hosted at, but the author has pulled down all copies. It is being mirrored here.

Chapters include:

  • Installing Python
  • Your First Python Program
  • Native Datatypes
  • The Power Of Introspection
  • Objects and Object-Orientation
  • Exceptions and File Handling
  • Regular Expressions
  • HTML Processing
  • XML Processing
  • Scripts and Streams
  • HTTP Web Services
  • SOAP Web Services
  • Unit Testing
  • Test-First Programming
  • Refactoring
  • Functional Programming
  • Dynamic functions
  • Performance Tuning

Read: Dive Into Python

A Byte of Python

My image
  • Author: Swaroop C H
  • Format: PDF, online HTML
  • Price: free

‘A Byte of Python’ is a free book on programming using the Python language. It serves as a tutorial or guide to the Python language for a beginner audience. If all you know about computers is how to save text files, then this is the book for you.

Chapters include:

  • Introduction
  • Installation
  • First Steps
  • Basics
  • Operators and Expressions
  • Control Flow
  • Functions
  • Modules
  • Data Structures
  • Problem Solving
  • Object Oriented Programming
  • Input Output
  • Exceptions
  • Standard Library
  • More
  • What Next

Learn Python The Hard Way

My image
  • Author: Zed A. Shaw
  • Format: online HTML
  • Price: Free

The book is a very beginner book for people who want to learn to code. If you can already code then the book will probably drive you insane. It’s intended for people who have no coding chops to build up their skills before starting a more detailed book.

The title says it’s the hard way to learn to write code; but it’s actually not. It’s only the “hard” way because it’s the way people used to teach things.

The book is very simple:

  • 52 exercises in all.
  • 26 cover just input/output, variables, and functions.
  • 26 cover logic (boolean algebra, if-statements, while-loops, etc.)

Each exercise is one or two pages and follows the exact same format. You type each one in (no copy-paste!), make it run, do the extra credit, and then move on. If you get stuck, at least type it in and skip the extra credit for later.

Chapters include:

  • The Hard Way Is Easier
  • Exercise 0: The Setup
  • Exercise 1: A Good First Program
  • Exercise 2: Comments And Pound Characters
  • Exercise 3: Numbers And Math
  • Exercise 4: Variables And Names
  • Exercise 5: More Variables And Printing
  • Exercise 6: Strings And Text
  • Exercise 7: More Printing
  • Exercise 8: Printing, Printing
  • Exercise 9: Printing, Printing, Printing
  • Exercise 10: What Was That?
  • Exercise 11: Asking Questions
  • Exercise 12: Prompting People
  • Exercise 13: Parameters, Unpacking, Variables
  • Exercise 14: Prompting And Passing
  • Exercise 15: Reading Files
  • Exercise 16: Reading And Writing Files
  • Exercise 17: More Files
  • Exercise 18: Names, Variables, Code, Functions
  • Exercise 19: Functions And Variables
  • Exercise 20: Functions And Files
  • Exercise 21: Functions Can Return Something
  • Exercise 22: What Do You Know So Far?
  • Exercise 23: Read Some Code
  • Exercise 24: More Practice
  • Exercise 25: Even More Practice
  • Exercise 26: Congratulations, Take A Test!
  • Exercise 27: Memorizing Logic
  • Exercise 28: Boolean Practice
  • Exercise 29: What If
  • Exercise 30: Else And If
  • Exercise 31: Making Decisions
  • Exercise 32: Loops And Lists
  • Exercise 33: While Loops
  • Exercise 34: Accessing Elements Of Lists
  • Exercise 35: Branches and Functions
  • Exercise 36: Designing and Debugging
  • Exercise 37: Symbol Review
  • Exercise 38: Reading Code
  • Exercise 39: Doing Things To Lists
  • Exercise 40: Dictionaries, Oh Lovely Dictionaries
  • Exercise 41: A Room With A View Of A Bear With A Broadsword
  • Exercise 42: Getting Classy
  • Exercise 43: You Make A Game
  • Exercise 44: Evaluating Your Game
  • Exercise 45: Is-A, Has-A, Objects, and Classes
  • Exercise 46: A Project Skeleton
  • Exercise 47: Automated Testing
  • Exercise 48: Advanced User Input
  • Exercise 49: Making Sentences
  • Exercise 50: Your First Work Assignment
  • Exercise 51: Reviewing Your Game
  • Exercise 52: Teach Someone Else What You Know
  • Next Steps
  • Advice From An Old Programmer

Practical Programming in Python

My image
  • Author: Jeffrey Elkner, Allen B. Downey, Chris Meyers, Brendan McCane, Iain Hewson, and Nick Meek
  • Format: PDF
  • Price: free

This is an open source introductory textbook to learn practical programming skills in the Python language. The textbook is meant as a first programming course and is tightly aligned with the University of Otago introductory programming course called Practical Programming.

This textbook is a modified version of “How to Think Like a Computer Scientist: Learning with Python 2nd Edition“, by Jeffrey Elkner, Allen B. Downey and Chris Meyers.

Chapters include:

  • The way of the program
  • Variables, expressions and statements
  • Python built-ins (batteries included)
  • Functions: part 1
  • Functions: part 2
  • Conditionals
  • Fruitful functions
  • Test driven development
  • Strings part 1
  • Files and modules
  • Iteration: part 1
  • Iteration: part 2
  • Strings part 2
  • Lists part 1
  • Lists part 2
  • Classes and objects
  • Graphical user interface programming
  • Case study: Catch
  • Case study: Catch continued
  • Dictionaries
  • Tuples
  • System programming
  • Case study 2
  • The last lecture

Invent Your Own Computer Games with Python

  • Author: Al Sweigart
  • Format: online HTML
  • Price: free (printed edition available on Amazon)

Invent Your Own Computer Games with Python is a free book that teaches you how to program in the Python programming language. Each chapter gives you the complete source code for a new game, and then teaches the programming concepts from the example. Games include Guess the Number, Hangman, Tic Tac Toe, and Reversi.

It was written to be understandable by kids as young as 10 to 12 years old, although it is great for anyone of any age who has never programmed before.

This fourth edition has revised and expanded content, including using the Pygame library to make 2D games with graphics, animation, and sound.

Chapters include:

  • Introduction
  • Chapter 1 – The Interactive Shell
  • Chapter 2 – Writing Programs
  • Chapter 3 – Guess the Number
  • Chapter 4 – A Joke-Telling Program
  • Chapter 5 – Dragon Realm
  • Chapter 6 – Using the Debugger
  • Chapter 7 – Designing Hangman with Flowcharts
  • Chapter 8 – Writing the Hangman Code
  • Chapter 9 – Extending Hangman
  • Chapter 10 – Tic-Tac-Toe
  • Chapter 11 – The Bagels Deduction Game
  • Chapter 12 – The Cartesian Coordinate System
  • Chapter 13 – Sonar Treasure Hunt
  • Chapter 14 – Caesar Cipher
  • Chapter 15 – The Reversegam Game
  • Chapter 16 – Reversegam AI Simulation
  • Chapter 17 – Creating Graphics
  • Chapter 18 – Animating Graphics
  • Chapter 19 – Collision Detection
  • Chapter 20 – Using Sounds And Images
  • Chapter 21 – A Dodger Game with Sounds and Images

Read: Invent Your Own Computer Games with Python

Buy print edition

Extending and Embedding the Python Interpreter

My image
  • Author: Python Software Foundation
  • Format: online HTML
  • Price: free

This document describes how to write modules in C or C++ to extend the Python interpreter with new modules. Those modules can define new functions but also new object types and their methods. The document also describes how to embed the Python interpreter in another application, for use as an extension language. Finally, it shows how to compile and link extension modules so that they can be loaded dynamically (at run time) into the interpreter, if the underlying operating system supports this feature.

This document assumes basic knowledge about Python.

Chapters include:

  • Extending Python with C or C++
  • A Simple Example
  • Intermezzo: Errors and Exceptions
  • Back to the Example
  • The Module’s Method Table and Initialization Function
  • Compilation and Linkage
  • Calling Python Functions from C
  • Extracting Parameters in Extension Functions
  • Keyword Parameters for Extension Functions
  • Building Arbitrary Values
  • Reference Counts
  • Writing Extensions in C++
  • Providing a C API for an Extension Module
  • Defining New Types
  • The Basics
  • Type Methods
  • Building C and C++ Extensions with distutils
  • Distributing your extension modules
  • Building C and C++ Extensions on Windows
  • A Cookbook Approach
  • Differences Between Unix and Windows
  • Using DLLs in Practice
  • Embedding Python in Another Application
  • Very High Level Embedding
  • Beyond Very High Level Embedding: An overview
  • Pure Embedding
  • Extending Embedded Python
  • Embedding Python in C++
  • Linking Requirements