The Quick Python Book, Third Edition
Naomi Ceder
  • MEAP began December 2016
  • Publication in December 2017 (estimated)
  • ISBN 9781617294037
  • 400 pages (estimated)
  • printed in black & white

GET MORE WITH MANNING

An eBook copy of the previous edition, The Quick Python Book, Second Edition, is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.


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.

After exploring Python's syntax, control flow, and basic data structures, the book shows how to create and deploy full applications and larger code libraries. It addresses established Python features as well as the advanced object-oriented options available in Python 3. Along the way, you'll survey the current Python development landscape, including Pythonic best practices, data extraction and cleaning, database access, and web frameworks.

"An absolutely marvelous introduction to Python."

~ William Wheeler

"I have a strong background on Java, and thanks to this book I could learn what I needed about Python."

~ Felipe Esteban Vildoso Castillo

"A great book to know the peculiarities of Python and start to program fast."

~ Carlos Fernandez Manzano

"A book that lead you from the basic knowledge of Python to the most interesting features, always using an accessible language."

~ Eros Pedrini

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. IDLE and the basic interactive mode

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 with list manipulations

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. py2exe and py2app

11.6.3. 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. Private variables and private methods

15.9. Using @property for more flexible instance variables

15.10. Scoping rules and namespaces for class instances

15.11. Destructors and memory management

15.12. Multiple inheritance

15.13. 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. init.py 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.1.5. Development and debugging tools and runtime services

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

What's inside

  • Concepts and Python 3 features
  • Regular expressions and OOP aspects
  • Python packaging and tools
  • Lots of exercises
  • All the Python you need - nothing you don't

About the author

Naomi Ceder is an elected fellow of the Python Software Foundation who has been learning, using, and teaching Python since 2001.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $39.99 pBook + eBook + liveBook
MEAP eBook $31.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks