Table of Contents

Python Pocket Reference

Table of Contents

1. Python Pocket Reference Introduction Book Conventions

Python Command-Line Usage

Python Command-Line Usage:

Python Environment Variables

Python Environment Variables:

Python Windows Launcher Usage

Python Windows Launcher Usage:

Python Built-in Types and Operators

Python Built-in Types and Operators:

Python Specific Built-in Types

Python Numbers

Python Numbers:

Python Strings

Python Strings:

Python Unicode Strings

Python Unicode Strings:

Python Lists

Python Lists:

Python Dictionaries

Python Dictionaries:

Python Tuples

Python Tuples:

Python Files

Python Files:

Python Sets

Python Sets:

Python Other Types and Conversions

Python Other Types and Conversions:

Python Statements and Syntax

Python Statements and Syntax:

Python Specific Statements

Python Specific Statements:

Python Namespace and Scope Rules

Python Namespace and Scope Rules:

Python Object-Oriented Programming

Python Object-Oriented Programming:

Python Operator Overloading Methods

Python Operator Overloading Methods:

Python Built-in Functions

Python Built-in Functions:

Python Built-in Exceptions

Python Built-in Exceptions:

Python Built-in Attributes

Python Built-in Attributes

Python Standard Library Modules

Python Standard Library Modules

Python sys Module

Python sys Module

Python string Module

Python string Module:

Python os System Module

Python os System Module:

Python re Pattern-Matching Module

Python re Pattern-Matching Module:

Python Object Persistence Modules

Python Object Persistence Modules:

Python tkinter GUI Module and Tools

Python tkinter GUI Module and Tools:

Python Internet Modules and Tools

Python Internet Modules and Tools

Python Other Standard Library Modules

Python Other Standard Library Modules:

Python Python SQL Database API

Python Python SQL Database API:

Python More Hints and Idioms

Python More Hints and Idioms:

Python Index


**************************************************************************************

Return to Python Bibliography

Fair Use Source: B00HZ41PGC

Python Pocket Reference by Mark Lutz

Python Pocket Reference Table of Contents

Python Pocket Reference Index

Python Pocket Reference Introduction

Updated for both Python 3.4 and 2.7, this convenient pocket guide is the perfect on-the-job quick reference. You’ll find concise, need-to-know information on Python types and statements, special method names, built-in functions and exceptions, commonly used standard library modules, and other prominent Python tools. The handy index lets you pinpoint exactly what you need.

Written by Mark Lutz—widely recognized as the world’s leading Python trainer—Python Pocket Reference is an ideal companion to O’Reilly’s classic Python tutorials, Learning Python and Programming Python, also written by Mark.

This fifth edition covers:

Built-in object types, including numbers, lists, dictionaries, and more Statements and syntax for creating and processing objects Functions and modules for structuring and reusing code Python’s object-oriented programming tools Built-in functions, exceptions, and attributes Special operator overloading methods Widely used standard library modules and extensions Command-line options and development tools Python idioms and hints The Python SQL Database API

Python Pocket Reference

Mark Lutz

Chapter 1. Python Pocket Reference

Introduction

Python is a general-purpose, multiparadigm, open source computer programming language, with support for object-oriented, functional, and procedural coding structures. It is commonly used both for standalone programs and for scripting applications in a wide variety of domains, and is generally considered to be one of the most widely used programming languages in the world.

Among Python’s features are an emphasis on code readability and library functionality, and a design that optimizes developer productivity, software quality, program portability, and component integration. Python programs run on most platforms in common use, including Unix and Linux, Windows and Macintosh, Java and .NET, Android and iOS, and more.

This pocket reference summarizes Python types and statements, special method names, built-in functions and exceptions, commonly used standard library modules, and other prominent Python tools. It is intended to serve as a concise reference tool for developers and is designed to be a companion to other books that provide tutorials, code examples, and other learning materials.

This fifth edition covers both Python 3.X and 2.X. It focuses primarily on 3.X, but also documents differences in 2.X along the way. Specifically, this edition has been updated to be current with Python versions 3.3 and 2.7 as well as prominent enhancements in the imminent 3.4 release, although most of its content also applies both to earlier and to later releases in the 3.X and 2.X lines.

This edition also applies to all major implementations of Python — including CPython, PyPy, Jython, IronPython, and Stackless — and has been updated and expanded for recent changes in language, libraries, and practice. Its changes include new coverage of the MRO and super(); formal algorithms of inheritance, imports, context managers, and block indentation; and commonly used library modules and tools, including json, timeit, random, subprocess, enum, and the new Windows launcher.

Book Conventions

The following notational conventions are used in this book:

[]

In syntax formats, items in brackets are optional; brackets are also used literally in some parts of Python’s syntax as noted where applicable (e.g., lists).

In syntax formats, items followed by an asterisk can be repeated zero or more times; star is also used literally in some parts of Python’s syntax (e.g., multiplication).

a | b

In syntax formats, items separated by a bar are alternatives; bar is also used literally in some parts of Python’s syntax (e.g., union).

Italic

Used for filenames and URLs, and to highlight new or important terms.

Constant width

Used for code, commands, and command-line options, and to indicate the names of modules, functions, attributes, variables, and methods.

Constant width italic

Used for replaceable parameter names in the syntax of command lines, expressions, functions, and methods.

Function()

Except where noted, callable functions and methods are denoted by trailing parentheses, to distinguish them from other types of attributes.

See “Section Header Name”

References to other sections in this book are given by section header text in double quotes.

Note

In this book, “3.X” and “2.X” mean that a topic applies to all commonly used releases in a Python line. More specific release numbers are used for topics of more limited scope (e.g., “2.7” means 2.7 only). Because future Python changes can invalidate applicability to future releases, also see Python’s “What’s New” documents, currently maintained at http://docs.python.org/3/whatsnew/index.html for Pythons released after this book.