O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Whirlwind Tour of Python

Book Description

To tap into the power of Python's open data science stack—including NumPy, Pandas, Matplotlib, Scikit-learn, and other tools—you first need to understand the syntax, semantics, and patterns of the Python language. This report provides a brief yet comprehensive introduction to Python for engineers, researchers, and data scientists who are already familiar with another programming language.

Author Jake VanderPlas, an interdisciplinary research director at the University of Washington, explains Python’s essential syntax and semantics, built-in data types and structures, function definitions, control flow statements, and more, using Python 3 syntax.

You’ll explore:

  • Python syntax basics and running Python code
  • Basic semantics of Python variables, objects, and operators
  • Built-in simple types and data structures
  • Control flow statements for executing code blocks conditionally
  • Methods for creating and using reusable functions
  • Iterators, list comprehensions, and generators
  • String manipulation and regular expressions
  • Python’s standard library and third-party modules
  • Python’s core data science tools
  • Recommended resources to help you learn more

Table of Contents

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