Author(s): Jake VanderPlas
Year: 2016
Cover
Additional Resources
Copyright
Table of Contents
Chapter 1. A Whirlwind Tour of Python
Introduction
Using Code Examples
Installation and Practical Considerations
The Zen of Python
How to Run Python Code
A Quick Tour of Python Language Syntax
Comments Are Marked by #
End-of-Line Terminates a Statement
Semicolon Can Optionally Terminate a Statement
Indentation: Whitespace Matters!
Whitespace Within Lines Does Not Matter
Parentheses Are for Grouping or Calling
Finishing Up and Learning More
Basic Python Semantics: Variables and Objects
Python Variables Are Pointers
Everything Is an Object
Basic Python Semantics: Operators
Arithmetic Operations
Bitwise Operations
Assignment Operations
Comparison Operations
Boolean Operations
Identity and Membership Operators
Built-In Types: Simple Values
Integers
Floating-Point Numbers
Complex Numbers
String Type
None Type
Boolean Type
Built-In Data Structures
Lists
Tuples
Dictionaries
Sets
More Specialized Data Structures
Control Flow
Conditional Statements: if, elif, and else
for loops
while loops
break and continue: Fine-Tuning Your Loops
Loops with an else Block
Defining and Using Functions
Using Functions
Defining Functions
Default Argument Values
*args and **kwargs: Flexible Arguments
Anonymous (lambda) Functions
Errors and Exceptions
Runtime Errors
Catching Exceptions: try and except
Raising Exceptions: raise
Diving Deeper into Exceptions
try…except…else…finally
Iterators
Iterating over lists
range(): A List Is Not Always a List
Useful Iterators
Specialized Iterators: itertools
List Comprehensions
Basic List Comprehensions
Multiple Iteration
Conditionals on the Iterator
Conditionals on the Value
Generators
Generator Expressions
Generator Functions: Using yield
Example: Prime Number Generator
Modules and Packages
Loading Modules: the import Statement
Importing from Python’s Standard Library
Importing from Third-Party Modules
String Manipulation and Regular Expressions
Simple String Manipulation in Python
Format Strings
Flexible Pattern Matching with Regular Expressions
A Preview of Data Science Tools
NumPy: Numerical Python
Pandas: Labeled Column-Oriented Data
Matplotlib: MATLAB-style scientific visualization
SciPy: Scientific Python
Other Data Science Packages
Resources for Further Learning
About the Author