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

Dive Into Python 3

Dive Into Python 3

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.

Continue reading

Dive Into Python

Dive Into Python

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 DiveIntoPython.org, but the author has pulled down all copies. It is being mirrored here.

Continue reading

A Byte of Python

A Byte of Python

A Byte of Python

Author Swaroop C H
Format PDF, Epub, 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.

This book will teach you to use Python version 3. There will also be guidance for you to adapt to the older and more common Python version 2 in the book.

Continue reading

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

http://learnpythonthehardway.org/book/

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

https://launchpad.net/practical-programming

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

http://docs.python.org/extending/index.html

Snake Wrangling for Kids: Learning to Program with Python

  • Author: Jason R. Briggs
  • Format: PDF
  • Price: free

Perhaps one of the best beginner books written on Python, designed for teaching kids ages 8 and older how to program, using Python 2.7.

This one is meant to be printed out and stapled together and given to your child as a gift. It comes in 3 different flavors (Mac, Linux, Windows).

Note: All PDF downloads have been depreciated by the author since the publication of the printed edition, Python for Kids, but updated versions are maintained and made available through a 3rd party, on Github, due to the original book’s generous Creative Commons (CC-BY-NC-SA) license.

The prebuilt PDF files are based on the original author’s Python 3 version of the book, and has been edited to work with Python 2.7. Please disregard anything you may read in the book’s preface about downloading Python 3. You need to get Python 2.7 for this version of the book.

Contents include:

  • Not all snakes will squish you
  • A Few Words About Language
  • The Order of Non-venomous Constricting Serpentes
  • Your First Python program
  • Your Second Python program. . .the same again?
  • multiplied by 3.57 equals
  • Use of brackets and “Order of Operations”
  • There’s nothing so fickle as a variable
  • Using Variable
  • A Piece of String?
  • Tricks with Strings
  • Not quite a shopping list
  • Tuples and Lists
  • Things to try
  • Turtles, and other slow moving creatures
  • Things to try
  • How to ask a question
  • Do this. . . or ELSE!!!
  • Do this. . . or do this. . . or do this. . . or ELSE!!!
  • Combining conditions
  • Emptiness
  • What’s the difference. . .?
  • Again and again
  • When is a block not square?
  • While we’re talking about looping
  • Things to try
  • Sort of like recycling
  • Bits and Pieces
  • Modules
  • Things to try
  • A short chapter about Files
  • Turtles galore
  • Colouring in
  • Darkness
  • Filling things
  • Things to try
  • A bit graphic
  • Quick Draw
  • Simple Drawing
  • Drawing Boxes
  • Drawing Arcs
  • Drawing Ovals
  • Drawing Polygons
  • Drawing Images
  • Basic Animation
  • Reacting to events
  • Where to go from here
  • Python Keywords
  • Built-in Functions
  • A Few Python Modules
  • Answers to “Things to try”

Get the book: Snake Wrangling for Kids (Mac)

Get the book: Snake Wrangling for Kids (Windows)

Get the book: Snake Wrangling for Kids (Linux)

Buy latest printed edition (paid link)

Download Python 2.7

As an Amazon Associate I earn from qualifying purchases made through Amazon links appearing on this website.

Python Reference Manual

  • Author: Guido van Rossum
  • Format: HTML
  • Price: free

This is a reference manual that describes the Python programming language. It is not meant as a tutorial. If you are using Python and wonder what the precise rules about a particular area of the language are, you should definitely be able to find them here.

There is currently only one Python implementation in widespread use (although alternate implementations exist), and its particular quirks are sometimes worth being mentioned, especially where the implementation imposes additional limitations. Therefore, you’ll find short “implementation notes'” sprinkled throughout the text. Each section has a number of subsections.

Chapters include:

  • Introduction
  • Lexical analysis
  • Data model
  • Execution model
  • Expressions
  • Simple statements
  • Compound statements
  • Top-level components
  • History and License

Visit Python Reference Manual

Text Processing in Python

Text Processing in Python
  • Author: David Mertz
  • Format: TXT
  • Price: free

This book is an example-driven, hands-on tutorial that carefully teaches programmers how to accomplish numerous text processing tasks using the Python language. Filled with concrete examples, it provides efficient and effective solutions to specific text processing problems and practical strategies for dealing with all types of text processing challenges.

The book begins with an introduction to text processing and contains a quick Python tutorial to get you up to speed. It then delves into essential text processing subject areas, including string operations, regular expressions, parsers and state machines, and Internet tools and techniques. Appendixes cover such important topics as data compression and Unicode. A comprehensive index and plentiful cross-referencing offer easy access to available information. In addition, exercises throughout the book provide readers with further opportunity to hone their skills either on their own or in the classroom. Source code, examples, and a regular expression chart are also provided on the author’s website.

Chapters include:

  • Introduction
  • Python Basics
  • Basic String Operations
  • Regular Expressions
  • Parsers and State-machines
  • Internet Tools and Techniques
  • A Selective and Impressionistic Short Review of Python
  • A Data Compression Primer
  • Understanding Unicode
  • A State-machine for Adding Markup to Text
  • Glossary Terms

http://gnosis.cx/TPiP/

Python Documentation

Python Documentation
  • Author: Python Software Foundation
  • Format: online HTML, archived HTML, archived PDF, archived plain text, EPUB
  • Price: free

This is the official Python documentation. One of the best places to start if you need information on Python. Always current & up to date. Everything is available for both online & offline viewing.

Topics include:

  • What’s New in Python XX (changes since previous major release)
  • Tutorial (start here)
  • Global Module Index (for quick access to all modules)
  • Library Reference (keep this under your pillow)
  • Macintosh Library Modules (this too, if you use a Macintosh)
  • Language Reference (for language lawyers)
  • Extending and Embedding (tutorial for C/C++ programmers)
  • Python/C API (reference for C/C++ programmers)
  • Documenting Python (information for documentation authors)
  • Installing Python Modules (information for installers & sys-admins)
  • Distributing Python Modules (sharing modules with others)

Documentation for Python 2.7

Documentation for Python 3.5

Documentation for Python 3.6

Documentation for Python 3.7