Leanpub Header

Skip to main content

Zero to Py

A Comprehensive Guide to Learning the Python Programming Language

A comprehensive guide to learning the Python programming language, written so to be accessible to readers of all levels, from beginner python developers to those who have some experience with python. Even more advanced users may find some utility from the later chapters.

Free With Membership

With Membership

Free!

$24.99

You pay

$24.99

Author earns

$19.99
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
53,387Words
About

About

About the Book

This book aims to be a comprehensive guide to learning the Python Programming Language, covering all the essential concepts and topics that a python developer needs to know. This book has been written so to be accessible to readers of all levels, whether you're just starting your journery into programming, or already have some experience with python. Even more advanced users may find some utility from the later chapters.

This book is divided into four parts.

In Part I of this book, we start by introducing you to the basics of Python, building a foundation on the fundamentals as we cover topics such as data types, operators, control flow, functions, and classes.

In Part II of this book, we build upon the foundation established in Part I and dive deeper into more advanced features of the Python programming language. We explore the more advanced features of Python, discussing topics such as generators, the data object model, metaclasses, etc, with the explicit aim to help you write more efficient and elegant code. And finally, we'll look into Python modules and packaging, so we can see how to take your python code and construct libraries which can be shared with the broader python community.

In Part III of this book, we will take a closer look at some of the "batteries included" sections of the Python standard library. These are the modules and packages that are included with every Python installation and provide a wide range of functionality that can be used to solve a variety of problems. We'll explore packages like functools, itertools, dataclasses, etc.

And finally in Part VI we'll dig into mechanisms for profiling and debugging python. Furthermore when we identify specific pain points in our implementation, we'll see how to refactor our projects to use performant C code for a boost in execution speed. We'll also look into how to use C debuggers to run the python interpreter, so we can debug our C extensions.

As a Leanpub publication, one of the benefits the platform provides is frictionless updates. As such, this book will act as a living document, recieving updates with every release of a minor version of Python, for as long as this book is in active release.

Share this book

Author

About the Author

Michael Green

Michael is currently a core library developer at Crunch Cloud Analytics, a subsidiary of YouGov. His software development experience includes full-stack web application development, data analysis and visualization, and computational modeling/scientific computing. He previous position was as a research assistant at the University of Missouri-Kansas City, where his work in nanophotonics has been featured and published in several of the top journals for chemistry, physics, and materials science.

Contents

Table of Contents

Zero to Py: A Comprehensive Guide to Learning the Python Programming Language

  1. Introduction

Part I: A Whirlwind Tour

  1. Chapter 0: System Setup
  2. Installing Python Natively
  3. Python Versions
  4. Windows
  5. macOS
  6. Linux
  7. What’s in a PATH?
  8. Setting up your dev environment
  9. Running Python
  10. A program that runs programs
  11. One interpreter, many modes
  12. Chapter 1. Fundamental data types
  13. But first, variables
  14. Primitives and Containers
  15. Mutability vs Immutability
  16. Introduction to Python’s data types
  17. Primitive Types
  18. Booleans
  19. Integers
  20. Floats
  21. Complex
  22. Strings
  23. Bytes
  24. Container Types
  25. Tuples and Lists
  26. Dictionaries
  27. Sets
  28. Python Objects
  29. References to Objects
  30. Chapter 2. Operators
  31. Arithmetic
  32. Assignment
  33. Packing operators
  34. Comparison
  35. Logical
  36. What is Truthy?
  37. Short-Circuits
  38. Logical Assignments
  39. Membership
  40. Bitwise
  41. Identity
  42. Chapter 3. Lexical Structure
  43. Line Structure
  44. Comments
  45. Explicit and Implicit Line Joining
  46. Indentation
  47. Chapter 4. Control Flow
  48. if, elif, and else
  49. while
  50. break
  51. continue
  52. for
  53. What is an Iterable?
  54. for/else and break
  55. Exception Handling
  56. raise from
  57. else and finally
  58. match
  59. type checking
  60. guards
  61. Or Patterns
  62. as
  63. Chapter 5. Functions
  64. Function Signatures
  65. Explicitly positional/key-value
  66. Default Values
  67. Mutable Types as Default Values
  68. Scope
  69. Nested Scopes
  70. nonlocal and global
  71. Closures
  72. Anonymous Functions
  73. Decorators
  74. Chapter 6. Classes
  75. data types as classes.
  76. __dunder__ methods
  77. The __init__ method
  78. Attributes
  79. Class Attributes
  80. A Functional Approach
  81. @staticmethod
  82. @classmethod

Part II. A Deeper Dive

  1. Chapter 7. Expressions, Comprehensions, and Generators
  2. Generator Expressions
  3. Generator Functions
  4. yield from
  5. List Comprehensions
  6. Dictionary Comprehensions
  7. Expressions and the Walrus Operator
  8. Chapter 8. Python’s Built-in Functions
  9. Type Conversions
  10. Mathematical Functions
  11. all() and any()
  12. dir()
  13. enumerate()
  14. eval() and exec()
  15. map()
  16. filter()
  17. input() and print()
  18. open()
  19. range()
  20. sorted()
  21. reversed()
  22. zip()
  23. Chapter 9. The Python Data Model
  24. Object Creation Using __new__ and __init__
  25. Singletons
  26. Rich Comparisons
  27. Operator Overloading
  28. String Representations
  29. Emulating Containers
  30. Emulating Functions
  31. Using Slots
  32. Customizing Attribute Access
  33. Iterators
  34. Lazy Evaluation
  35. Context Managers
  36. Descriptors
  37. Chapter 10. Concepts in Object-Oriented Programming
  38. Inheritance
  39. Calling the Super Class using super()
  40. Multiple Inheritance and Method Resolution Order
  41. Encapsulation
  42. Polymorphism
  43. Chapter 11. Metaclasses
  44. Chapter 12. The Data Types, Revisited.
  45. Numbers
  46. Integers
  47. Bits and Bytes
  48. Floats
  49. Float Methods
  50. Hex Values
  51. Complex Numbers
  52. Strings
  53. Split and Join
  54. Search and Replace
  55. Paddings
  56. Formatting
  57. Translating
  58. Partitioning
  59. Prefixes and Suffixes
  60. Boolean Checks
  61. Case Methods
  62. Encodings
  63. Bytes
  64. Decoding
  65. Hex Values
  66. Tuples
  67. Lists
  68. Counting and Indexing
  69. Copying
  70. Mutations
  71. Orderings
  72. Dictionaries
  73. Iter Methods
  74. Getter/Setter Methods
  75. Mutations
  76. Creating new Dictionaries
  77. Sets
  78. Mutations
  79. Set Theory
  80. Boolean Checks
  81. Copying
  82. Chapter 13. Type Hints
  83. Incorporating Type Hints
  84. Union types
  85. Optional
  86. type|None
  87. Literal
  88. Final
  89. Type aliases
  90. NewType
  91. Generic Types
  92. Protocols
  93. Runtime type checking
  94. TypedDict
  95. Chapter 14. Modules, Packages, and Namespaces
  96. Modules
  97. Module Attributes
  98. if __name__ == "__main__":
  99. Packages
  100. Imports within packages
  101. Installation

Part III. The Python Standard Library

  1. Chapter 15. Virtual Environments
  2. Chapter 16. Copy
  3. Chapter 17. Itertools
  4. Chaining Iterables
  5. Filtering Iterables
  6. Cycling Through Iterables
  7. Creating Groups
  8. Slicing Iterables
  9. Zip Longest
  10. Chapter 18. Functools
  11. Partials
  12. Reduce
  13. Pipes
  14. Caching
  15. Dispatching
  16. Chapter 19. Enums, NamedTuples, and Dataclasses
  17. Enums
  18. NamedTuples
  19. Dataclasses
  20. Chapter 20. Multithreading and Multiprocessing
  21. Multithreading
  22. Thread Locks
  23. Multiprocessing
  24. Process and Pool
  25. Process Locks
  26. Pipes and Queues
  27. concurrent.futures
  28. Chapter 21. Asyncio
  29. Coroutines
  30. Tasks and Task Groups
  31. ExceptionGroup and Exception unpacking

Part VI. The Underbelly of the Snake

  1. Chapter 22. Debugging
  2. pdb
  3. Other Debuggers
  4. Chapter 23. Profiling
  5. cProfile
  6. flameprof
  7. snakeviz
  8. memory_profiler
  9. Chapter 24. C extensions
  10. Hello World
  11. hello_world.c
  12. setup.py
  13. Passing data in and out of Python
  14. Memory Management
  15. Parsing Arguments
  16. Parsing Tuple Arguments
  17. Parsing Keyword Arguments
  18. Creating PyObjects
  19. Importing Modules
  20. Defining New Types
  21. Stack type
  22. Debugging C extensions

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub