The Quick Python Book, Third Edition
Naomi Ceder
Foreword by Nicholas Tollervey
  • May 2018
  • ISBN 9781617294037
  • 472 pages
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

Naomi's book epitomizes what it is to be Pythonic: beautiful is better than ugly, simple is better than complex, and readability counts.

From the Foreword by Nicholas Tollervey, Python Software Foundation

This third revision of Manning's popular The Quick Python Book offers a clear, crisp updated introduction to the elegant Python programming language and its famously easy-to-read syntax. Written for programmers new to Python, this latest edition includes new exercises throughout. It covers features common to other languages concisely, while introducing Python's comprehensive standard functions library and unique features in detail.

About the Technology

Initially Guido van Rossum's 1989 holiday project, Python has grown into an amazing computer language. It's a joy to learn and read, and powerful enough to handle everything from low-level system resources to advanced applications like deep learning. Elegantly simple and complete, it also boasts a massive ecosystem of libraries and frameworks. Python programmers are in high demand--you can't afford not to be fluent!

About the book

The Quick Python Book, Third Edition is a comprehensive guide to the Python language by a Python authority, Naomi Ceder. With the personal touch of a skilled teacher, she beautifully balances details of the language with the insights and advice you need to handle any task. Extensive, relevant examples and learn-by-doing exercises help you master each important concept the first time through. Whether you're scraping websites or playing around with nested tuples, you'll appreciate this book's clarity, focus, and attention to detail.

Table of Contents detailed table of contents

Part 1: Starting out

1. About Python

1.1. Why should I use Python?

1.2. What Python does well

1.2.1. Python is easy to use

1.2.2. Python is expressive

1.2.3. Python is readable

1.2.4. Python is complete-"batteries included"

1.2.5. Python is cross-platform

1.2.6. Python is free

1.3. What Python doesn’t do as well

1.3.1. Python is not the fastest language

1.3.2. Python doesn’t have the most libraries

1.3.3. Python doesn’t check variable types at compile time

1.3.4. Python doesn’t have much mobile support

1.3.5. Python doesn’t use multiple processors well

1.4. Why learn Python 3?

1.5. Summary

2. Getting started

2.1. Installing Python

2.2. Basic interactive mode and IDLE

2.2.1. The basic interactive mode

2.2.2. The IDLE integrated development environment

2.2.3. Choosing between basic interactive mode and IDLE

2.3. Using IDLE’s Python Shell window

2.4. Hello, world

2.5. Using the interactive prompt to explore Python

2.6. Summary

3. The Quick Python overview

3.1. Python synopsis

3.2. Built-in data types

3.2.1. Numbers

3.2.2. Lists

3.2.3. Tuples

3.2.4. Strings

3.2.5. Dictionaries

3.2.6. Sets

3.2.7. File objects

3.3. Control flow structures

3.3.1. Boolean values and expressions

3.3.2. The if-elif-else statement

3.3.3. The while loop

3.3.4. The for loop

3.3.5. Function definition

3.3.6. Exceptions

3.3.7. Context handling using with

3.4. Module creation

3.5. Object-oriented programming

3.6. Summary

Part 2: The essentials

4. The absolute basics

4.1. Indentation and block structuring

4.2. Differentiating comments

4.3. Variables and assignments

4.4. Expressions

4.5. Strings

4.6. Numbers

4.6.1. Built-in numeric functions

4.6.2. Advanced numeric functions

4.6.3. Numeric computation

4.6.4. Complex numbers

4.6.5. Advanced complex-number functions

4.7. The None value

4.8. Getting input from the user

4.9. Built-in operators

4.10. Basic Python style

4.11. Summary

5. Lists, tuples, and sets

5.1. Lists are like arrays

5.2. List indices

5.3. Modifying lists

5.4. Sorting lists

5.4.1. Custom sorting

5.4.2. The sorted() function

5.5. Other common list operations

5.5.1. List membership with the in operator

5.5.2. List concatenation with the + operator

5.5.3. List initialization with the * operator

5.5.4. List minimum or maximum with min and max

5.5.5. List search with index

5.5.6. List matches with count

5.5.7. Summary of list operations

5.6. Nested lists and deep copies

5.7. Tuples

5.7.1. Tuple basics

5.7.2. One-element tuples need a comma

5.7.3. Packing and unpacking tuples

5.7.4. Converting between lists and tuples

5.8. Sets

5.8.1. Set operations

5.8.2. Frozensets

5.9. Summary

6. Strings

6.1. Strings as sequences of characters

6.2. Basic string operations

6.3. Special characters and escape sequences

6.3.1. Basic escape sequences

6.3.2. Numeric (octal and hexadecimal) and Unicode escape sequences

6.3.3. Printing vs. evaluating strings with special characters

6.4. String methods

6.4.1. The split and join string methods

6.4.2. Converting strings to numbers

6.4.3. Getting rid of extra whitespace

6.4.4. String searching

6.4.5. Modifying strings

6.4.6. Modifying strings

6.4.7. Useful methods and constants

6.5. Converting from objects to strings

6.6. Using the format method

6.6.1. The format method and positional parameters

6.6.2. The format method and named parameters

6.6.3. Format specifiers

6.7. Formatting strings with %

6.7.1. Using formatting sequences

6.7.2. Named parameters and formatting sequences

6.8. String Interpolation

6.9. Bytes

6.10. Summary

7. Dictionaries

7.1. What is a dictionary?

7.1.1. Why dictionaries are called dictionaries

7.2. Other dictionary operations

7.3. Word counting

7.4. What can be used as a key?

7.5. Sparse matrices

7.6. Dictionaries as caches

7.7. Efficiency of dictionaries

7.8. Summary

8. Control flow

8.1. The while loop

8.1.1. The break and continue statements

8.2. The if-elif-else statement

8.3. The for loop

8.3.1. The range function

8.3.2. Using break and continue in for loops

8.3.3. The for loop and tuple unpacking

8.3.4. The enumerate function

8.3.5. The zip function

8.4. List and dictionary comprehensions

8.4.1. Generator Expressions

8.5. Statements, blocks, and indentation

8.6. Boolean values and expressions

8.6.1. Most Python objects can be used as Booleans

8.6.2. Comparison and Boolean operators

8.7. Writing a simple program to analyze a text file

8.8. Summary

9. Functions

9.1. Basic function definitions

9.2. Function parameter options

9.2.1. Positional parameters

9.2.2. Passing arguments by parameter name

9.2.3. Variable numbers of arguments

9.2.4. Mixing argument-passing techniques

9.3. Mutable objects as arguments

9.4. Local, nonlocal, and global variables

9.5. Assigning functions to variables

9.6. lambda expressions

9.7. Generator functions

9.8. Decorators

9.9. Summary

10. Modules and scoping rules

10.1. What is a module?

10.2. A first module

10.3. The import statement

10.4. The module search path

10.4.1. Where to place your own modules

10.5. Private names in modules

10.6. Library and third-party modules

10.7. Python scoping rules and namespaces

10.8. Summary

11. Python programs

11.1. Creating a very basic program

11.1.1. Starting a script from a command line

11.1.2. Command-line arguments

11.1.3. Redirecting the input and output of a script

11.1.4. The argparse module

11.1.5. Using the fileinput module

11.2. Making a script directly executable on UNIX

11.3. Scripts on Mac OS X

11.4. Script execution options in Windows

11.4.1. Starting a script from a command window or PowerShell

11.4.2. Other Windows options

11.5. Programs and modules

11.6. Distributing Python applications

11.6.1. wheels

11.6.2. zipapp and pex

11.6.3. py2exe and py2app

11.6.4. Creating executable programs with freeze

11.7. Summary

12. Using the filesystem

12.1. os and os.path vs. pathlib

12.2. Paths and pathnames

12.2.1. Absolute and relative paths

12.2.2. The current working directory

12.2.3. Accessing directories with pathlib

12.2.4. Manipulating pathnames

12.2.5. Manipulating pathnames with pathlib

12.2.6. Useful constants and functions

12.3. Getting information about files

12.3.1. Getting information about files with scandir

12.4. More filesystem operations

12.4.1. More filesystem operations with pathlib

12.5. Processing all files in a directory subtree

12.6. Summary

13. Reading and writing files

13.1. Opening files and file objects

13.2. Closing files

13.3. Opening files in write or other modes

13.4. Functions to read and write text or binary data

13.4.1. Using binary mode

13.5. Reading and writing with pathlib

13.6. Screen input/output and redirection

13.7. Reading structured binary data with the struct module

13.8. Pickling objects into files

13.8.1. Reasons not to pickle

13.9. Shelving objects

13.10. Summary

14. Exceptions

14.1. Introduction to exceptions

14.1.1. General philosophy of errors and exception handling

14.1.2. A more formal definition of exceptions

14.1.3. User-defined exceptions

14.2. Exceptions in Python

14.2.1. Types of Python exceptions

14.2.2. Raising exceptions

14.2.3. Catching and handling exceptions

14.2.4. Defining new exceptions

14.2.5. Debugging programs with the assert statement

14.2.6. The exception inheritance hierarchy

14.2.7. Example: a disk-writing program in Python

14.2.8. Example: exceptions in normal evaluation

14.2.9. Where to use exceptions

14.3. Context managers using with

14.4. Summary

Part 3: Advanced language features

15. Classes and object-oriented programming

15.1. Defining classes

15.1.1. Using a class instance as a structure or record

15.2. Instance variables

15.3. Methods

15.4. Class variables

15.4.1. An oddity with class variables

15.5. Static methods and class methods

15.5.1. Static methods

15.5.2. Class methods

15.6. Inheritance

15.7. Inheritance with class and instance variables

15.8. Recap - basics of Python classes

15.9. Private variables and private methods

15.10. Using @property for more flexible instance variables

15.11. Scoping rules and namespaces for class instances

15.12. Destructors and memory management

15.13. Multiple inheritance

15.14. Summary

16. Regular expressions

16.1. What is a regular expression?

16.2. Regular expressions with special characters

16.3. Regular expressions and raw strings

16.3.1. Raw strings to the rescue

16.4. Extracting matched text from strings

16.5. Substituting text with regular expressions

16.6. Summary

17. Data types as objects

17.1. Types are objects, too

17.2. Using types

17.3. Types and user-defined classes

17.4. Duck typing

17.5. What is a special method attribute?

17.6. Making an object behave like a list

17.7. The getitem special method attribute

17.7.1. How it works

17.7.2. Implementing full list functionality

17.8. Giving an object full list capability

17.9. Subclassing from built-in types

17.9.1. Subclassing list

17.9.2. Subclassing UserList

17.10. When to use special method attributes

17.11. Summary

18. Packages

18.1. What is a package?

18.2. A first example

18.3. A concrete example

18.3.1. files in packages

18.3.2. Basic use of the mathproj package

18.3.3. Loading subpackages and submodules

18.3.4. import statements within packages

18.4. The all attribute

18.5. Proper use of packages

18.6. Summary

19. Using Python libraries

19.1. "Batteries included"-the standard library

19.1.1. Managing various data types

19.1.2. Manipulating files and storage

19.1.3. Accessing operating system services

19.1.4. Using internet protocols and formats

19.2. Moving beyond the standard library

19.3. Adding more Python libraries

19.4. Installing Python libraries using pip and venv

19.4.1. Installing with the -user flag

19.4.2. Virtual environments

19.5. PyPI, a.k.a. "the Cheese Shop"

19.6. Summary

Part 4: Working with data

20. Basic File Wrangling

20.1. The problem: the never-ending flow of data files

20.2. Scenario: The product feed from hell

20.3. More organization

20.4. Saving storage space: compression and grooming

20.4.1. Compressing files

20.4.2. Grooming files

20.5. Summary

21. Processing Data Files

21.1. Welcome to ETL

21.2. Reading text files

21.2.1. Text encoding - ASCII, Unicode, and others

21.2.2. Unstructured text

21.2.3. Delimited "flat" files

21.2.4. The csv module

21.2.5. Reading a csv file as a list of dictionaries

21.3. Excel files

21.4. Data cleaning

21.4.1. Cleaning

21.4.2. Sorting

21.4.3. Data cleaning issues and pitfalls

21.5. Writing data files

21.5.1. CSV and other delimited files

21.5.2. Writing Excel files

21.5.3. Packaging data files

21.6. Summary

22. Data over the Network

22.1. Fetching files

22.1.1. Using Python to fetch files from an FTP server

22.1.2. Fetching files with SFTP

22.1.3. Retrieving files over HTTP/HTTPS

22.2. Fetching data via an API

22.3. Structured data formats

22.3.1. JSON data

22.3.2. XML data

22.4. Scraping web data

22.5. Summary

23. Saving Data

23.1. Relational databases

23.1.1. The Python Database API

23.2. SQLite - using the sqlite3 database

23.3. Using MySQL, PostgreSQL, and other relational databases

23.4. Making database handling easier with an ORM

23.4.1. SQLAlchemy

23.4.2. Using Alembic for database schema changes

23.5. NoSQL databases

23.6. Key:value stores with Redis

23.7. Documents in MongoDB

23.8. Summary

24. Exploring Data

24.1. Python tools for data exploration

24.1.1. Python’s advantages for exploring data

24.1.2. Python can be better than spreadsheet

24.2. Jupyter Notebook

24.2.1. Starting a kernel

24.2.2. Executing code in a cell

24.3. Python and Pandas

24.3.1. Why you might want to use Pandas

24.3.2. Installing Pandas

24.3.3. Data Frames

24.4. Data Cleaning

24.4.1. Loading and saving data with pandas

24.4.2. Data Cleaning with a data frame

24.5. Data aggregation and manipulation

24.5.1. Merging data frames

24.5.2. Selecting data

24.5.3. Grouping and aggregation

24.6. Plotting data

24.7. Why you might not want to use pandas

24.8. Summary

Case Study

Downloading the data

Parsing the inventory data

Selecting a station based on latitude and longitude

Selecting a station and getting the station metadata

Fetching and parsing the actual weather data

Fetching the data

Parsing the weather data

Saving the weather data in a database (Optional)

Selecting and graphing data

Using pandas to graph our data

Appendix A

A guide to Python’s documentation

Accessing Python documentation on the Web

Browsing Python documentation on your computer

Downloading documentation

Best practices - How to become a Pythonista

10 tips for becoming a Pythonista

The Python manual of style

PEP 8 - Style Guide for Python Code


Code layout


Naming conventions

Programming recommendations

The Zen of Python

What's inside

  • Clear coverage of Python 3
  • Core libraries, packages, and tools
  • In-depth exercises
  • Five new data science-related chapters

About the reader

Written for readers familiar with programming concepts--no Python experience assumed.

If you're getting started with Python, then MIT lecturer Ana Bell's liveVideo course Get Programming with Python in Motion is perfect alongside this book, offering exercises and easy-to-digest lessons o get you started as fast as possible.

About the author

Naomi Ceder is chair of the Python Software Foundation. She has been learning, using, and teaching Python since 2001.

We interviewed Naomi as a part of our Six Questions series. Check it out here.

placing your order...

Don't refresh or navigate away from the page.
print book $39.99 pBook + eBook + liveBook
includes previous edition eBook
Additional shipping charges may apply
The Quick Python Book, Third Edition (print book) added to cart
continue shopping
go to cart

eBook $31.99 3 formats + liveBook
includes previous edition eBook
The Quick Python Book, Third Edition (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks