Duration
5 days
Part I. Getting Started
- A Python Q&A Session
- Why Do People Use Python?
- Software Quality
- Developer Productivity
- Is Python a “Scripting Language”?
- OK, but What’s the Downside?
- Who Uses Python Today?
- What Can I Do with Python?
- Systems Programming
- GUIs
- Internet Scripting
- Component Integration
- Database Programming
- Rapid Prototyping
- Numeric and Scientific Programming
- And More: Gaming, Images, Data Mining, Robots, Excel
- How Is Python Developed and Supported?
- Open Source Tradeoffs
- What Are Python’s Technical Strengths?
- It’s Object-Oriented and Functional
- It’s Free
- It’s Portable
- It’s Powerful
- It’s Mixable
- It’s Relatively Easy to Use
- It’s Relatively Easy to Learn
- It’s Named After Monty Python
- How Does Python Stack Up to Language X?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- How Python Runs Programs
- Introducing the Python Interpreter
- Program Execution
- The Programmer’s View
- Python’s View
- Execution Model Variations
- Python Implementation Alternatives
- Execution Optimization Tools
- Frozen Binaries
- Future Possibilities?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- How You Run Programs
- The Interactive Prompt
- Starting an Interactive Session
- The System Path
- New Windows Options in 3.3: PATH, Launcher
- Where to Run: Code Directories
- What Not to Type: Prompts and Comments
- Running Code Interactively
- Why the Interactive Prompt?
- Usage Notes: The Interactive Prompt
- System Command Lines and Files
- A First Script
- Running Files with Command Lines
- Command-Line Usage Variations
- Usage Notes: Command Lines and Files
- Unix-Style Executable Scripts: #!
- Unix Script Basics
- The Unix env Lookup Trick
- The Python 3.3 Windows Launcher: #! Comes to Windows
- Clicking File Icons
- Icon-Click Basics
- Clicking Icons on Windows
- The input Trick on Windows
- Other Icon-Click Limitations
- Module Imports and Reloads
- Import and Reload Basics
- The Grander Module Story: Attributes
- Usage Notes: import and reload
- Using exec to Run Module Files
- The IDLE User Interface
- IDLE Startup Details
- IDLE Basic Usage
- IDLE Usability Features
- Advanced IDLE Tools
- Usage Notes: IDLE
- Other IDEs
- Other Launch Options
- Embedding Calls
- Frozen Binary Executables
- Text Editor Launch Options
- Still Other Launch Options
- Future Possibilities?
- Which Option Should I Use?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part I Exercises
Part II. Types and Operations
- Introducing Python Object Types
- The Python Conceptual Hierarchy
- Why Use Built-in Types?
- Python’s Core Data Types
- Numbers
- Strings
- Sequence Operations
- Immutability
- Type-Specific Methods
- Getting Help
- Other Ways to Code Strings
- Unicode Strings
- Pattern Matching
- Lists
- Sequence Operations
- Type-Specific Operations
- Bounds Checking
- Nesting
- Comprehensions
- Dictionaries
- Mapping Operations
- Nesting Revisited
- Missing Keys: if Tests
- Sorting Keys: for Loops
- Iteration and Optimization
- Tuples
- Why Tuples?
- Files
- Binary Bytes Files
- Unicode Text Files
- Other File-Like Tools
- Other Core Types
- How to Break Your Code’s Flexibility
- User-Defined Classes
- And Everything Else
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Numeric Types
- Numeric Type Basics
- Numeric Literals
- Built-in Numeric Tools
- Python Expression Operators
- Numbers in Action
- Variables and Basic Expressions
- Numeric Display Formats
- Comparisons: Normal and Chained
- Division: Classic, Floor, and True
- Integer Precision
- Complex Numbers
- Hex, Octal, Binary: Literals and Conversions
- Bitwise Operations
- Other Built-in Numeric Tools
- Other Numeric Types
- Decimal Type
- Fraction Type
- Sets
- Booleans
- Numeric Extensions
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- The Dynamic Typing Interlude
- The Case of the Missing Declaration Statements
- Variables, Objects, and References
- Types Live with Objects, Not Variables
- Objects Are Garbage-Collected
- Shared References
- Shared References and In-Place Changes
- Shared References and Equality
- Dynamic Typing Is Everywhere
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- String Fundamentals
- This Chapter’s Scope
- Unicode: The Short Story
- String Basics
- String Literals
- Single- and Double-Quoted Strings Are the Same
- Escape Sequences Represent Special Characters
- Raw Strings Suppress Escapes
- Triple Quotes Code Multiline Block Strings
- Strings in Action
- Basic Operations
- Indexing and Slicing
- String Conversion Tools
- Changing Strings I
- String Methods
- Method Call Syntax
- Methods of Strings
- String Method Examples: Changing Strings II
- String Method Examples: Parsing Text
- Other Common String Methods in Action
- The Original string Module’s Functions (Gone in 3.X)
- String Formatting Expressions
- Formatting Expression Basics
- Advanced Formatting Expression Syntax
- Advanced Formatting Expression Examples
- Dictionary-Based Formatting Expressions
- String Formatting Method Calls
- Formatting Method Basics
- Adding Keys, Attributes, and Offsets
- Advanced Formatting Method Syntax
- Advanced Formatting Method Examples
- Comparison to the % Formatting Expression
- Why the Format Method?
- General Type Categories
- Types Share Operation Sets by Categories
- Mutable Types Can Be Changed in Place
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Lists and Dictionaries
- Lists
- Lists in Action
- Basic List Operations
- List Iteration and Comprehensions
- Indexing, Slicing, and Matrixes
- Changing Lists in Place
- Dictionaries
- Dictionaries in Action
- Basic Dictionary Operations
- Changing Dictionaries in Place
- More Dictionary Methods
- Example: Movie Database
- Dictionary Usage Notes
- Other Ways to Make Dictionaries
- Dictionary Changes in Python 3.X and 2.7
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Tuples, Files, and Everything Else
- Tuples
- Tuples in Action
- Why Lists and Tuples?
- Records Revisited: Named Tuples
- Files
- Opening Files
- Using Files
- Files in Action
- Text and Binary Files: The Short Story
- Storing Python Objects in Files: Conversions
- Storing Native Python Objects: pickle
- Storing Python Objects in JSON Format
- Storing Packed Binary Data: struct
- File Context Managers
- Other File Tools
- Core Types Review and Summary
- Object Flexibility
- References Versus Copies
- Comparisons, Equality, and Truth
- The Meaning of True and False in Python
- Python’s Type Hierarchies
- Type Objects
- Other Types in Python
- Built-in Type Gotchas
- Assignment Creates References, Not Copies
- Repetition Adds One Level Deep
- Beware of Cyclic Data Structures
- Immutable Types Can’t Be Changed in Place
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part II Exercises
Part III. Statements and Syntax
- Introducing Python Statements
- The Python Conceptual Hierarchy Revisited
- Python’s Statements
- A Tale of Two ifs
- What Python Adds
- What Python Removes
- Why Indentation Syntax?
- A Few Special Cases
- A Quick Example: Interactive Loops
- A Simple Interactive Loop
- Doing Math on User Inputs
- Handling Errors by Testing Inputs
- Handling Errors with try Statements
- Nesting Code Three Levels Deep
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Assignments, Expressions, and Prints
- Assignment Statements
- Assignment Statement Forms
- Sequence Assignments
- Extended Sequence Unpacking in Python 3.X
- Multiple-Target Assignments
- Augmented Assignments
- Variable Name Rules
- Expression Statements
- Expression Statements and In-Place Changes
- Print Operations
- The Python 3.X print Function
- The Python 2.X print Statement
- Print Stream Redirection
- Version-Neutral Printing
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- if Tests and Syntax Rules
- if Statements
- General Format
- Basic Examples
- Multiway Branching
- Python Syntax Revisited
- Block Delimiters: Indentation Rules
- Statement Delimiters: Lines and Continuations
- A Few Special Cases
- Truth Values and Boolean Tests
- The if/else Ternary Expression
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- while and for Loops
- while Loops
- General Format
- Examples
- break, continue, pass, and the Loop else
- General Loop Format
- pass
- continue
- break
- Loop else
- for Loops
- General Format
- Examples
- Loop Coding Techniques
- Counter Loops: range
- Sequence Scans: while and range Versus for
- Sequence Shufflers: range and len
- Nonexhaustive Traversals: range Versus Slices
- Changing Lists: range Versus Comprehensions
- Parallel Traversals: zip and map
- Generating Both Offsets and Items: enumerate
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Iterations and Comprehensions
- Iterations: A First Look
- The Iteration Protocol: File Iterators
- Manual Iteration: iter and next
- Other Built-in Type Iterables
- List Comprehensions: A First Detailed Look
- List Comprehension Basics
- Using List Comprehensions on Files
- Extended List Comprehension Syntax
- Other Iteration Contexts
- New Iterables in Python 3.X
- Impacts on 2.X Code: Pros and Cons
- The range Iterable
- The map, zip, and filter Iterables
- Multiple Versus Single Pass Iterators
- Dictionary View Iterables
- Other Iteration Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- The Documentation Interlude
- Python Documentation Sources
- # Comments
- The dir Function
- Docstrings: __doc__
- PyDoc: The help Function
- PyDoc: HTML Reports
- Beyond docstrings: Sphinx
- The Standard Manual Set
- Web Resources
- Published Books
- Common Coding Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part III Exercises
Part IV. Functions and Generators
- Function Basics
- Why Use Functions?
- Coding Functions
- def Statements
- def Executes at Runtime
- A First Example: Definitions and Calls
- Definition
- Calls
- Polymorphism in Python
- A Second Example: Intersecting Sequences
- Definition
- Calls
- Polymorphism Revisited
- Local Variables
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Scopes
- Python Scope Basics
- Scope Details
- Name Resolution: The LEGB Rule
- Scope Example
- The Built-in Scope
- The global Statement
- Program Design: Minimize Global Variables
- Program Design: Minimize Cross-File Changes
- Other Ways to Access Globals
- Scopes and Nested Functions
- Nested Scope Details
- Nested Scope Examples
- Factory Functions: Closures
- Retaining Enclosing Scope State with Defaults
- The nonlocal Statement in 3.X
- nonlocal Basics
- nonlocal in Action
- Why nonlocal? State Retention Options
- State with nonlocal: 3.X only
- State with Globals: A Single Copy Only
- State with Classes: Explicit Attributes (Preview)
- State with Function Attributes: 3.X and 2.X
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Arguments
- Argument-Passing Basics
- Arguments and Shared References
- Avoiding Mutable Argument Changes
- Simulating Output Parameters and Multiple Results
- Special Argument-Matching Modes
- Argument Matching Basics
- Argument Matching Syntax
- The Gritty Details
- Keyword and Default Examples
- Arbitrary Arguments Examples
- Python 3.X Keyword-Only Arguments
- The min Wakeup Call!
- Full Credit
- Bonus Points
- The Punch Line
- Generalized Set Functions
- Emulating the Python 3.X print Function
- Using Keyword-Only Arguments
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Advanced Function Topics
- Function Design Concepts
- Recursive Functions
- Summation with Recursion
- Coding Alternatives
- Loop Statements Versus Recursion
- Handling Arbitrary Structures
- Function Objects: Attributes and Annotations
- Indirect Function Calls: “First Class” Objects
- Function Introspection
- Function Attributes
- Function Annotations in 3.X
- Anonymous Functions: lambda
- lambda Basics
- Why Use lambda?
- How (Not) to Obfuscate Your Python Code
- Scopes: lambdas Can Be Nested Too
- Functional Programming Tools
- Mapping Functions over Iterables: map
- Selecting Items in Iterables: filter
- Combining Items in Iterables: reduce
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Comprehensions and Generations
- List Comprehensions and Functional Tools
- List Comprehensions Versus map
- Adding Tests and Nested Loops: filter
- Example: List Comprehensions and Matrixes
- Don’t Abuse List Comprehensions: KISS
- Generator Functions and Expressions
- Generator Functions: yield Versus return
- Generator Expressions: Iterables Meet Comprehensions
- Generator Functions Versus Generator Expressions
- Generators Are Single-Iteration Objects
- Generation in Built-in Types, Tools, and Classes
- Example: Generating Scrambled Sequences
- Don’t Abuse Generators: EIBTI
- Example: Emulating zip and map with Iteration Tools
- Comprehension Syntax Summary
- Scopes and Comprehension Variables
- Comprehending Set and Dictionary Comprehensions
- Extended Comprehension Syntax for Sets and Dictionaries
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- The Benchmarking Interlude
- Timing Iteration Alternatives
- Timing Module: Homegrown
- Timing Script
- Timing Results
- Timing Module Alternatives
- Other Suggestions
- Timing Iterations and Pythons with timeit
- Basic timeit Usage
- Benchmark Module and Script: timeit
- Benchmark Script Results
- More Fun with Benchmarks
- Other Benchmarking Topics: pystones
- Function Gotchas
- Local Names Are Detected Statically
- Defaults and Mutable Objects
- Functions Without returns
- Miscellaneous Function Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part IV Exercises
Programme scope, delivery arrangements and suitability are confirmed during enquiry.