Zero to Py
Zero to Py
A Comprehensive Guide to Learning the Python Programming Language
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.
Table of Contents
-
Zero to Py: A Comprehensive Guide to Learning the Python Programming Language
- Introduction
-
Part I: A Whirlwind Tour
-
Chapter 0: System Setup
-
Installing Python Natively
- Python Versions
- Windows
- macOS
- Linux
- What’s in a PATH?
- Setting up your dev environment
-
Running Python
- A program that runs programs
- One interpreter, many modes
-
Installing Python Natively
-
Chapter 1. Fundamental data types
- But first, variables
- Primitives and Containers
- Mutability vs Immutability
-
Introduction to Python’s data types
-
Primitive Types
- Booleans
- Integers
- Floats
- Complex
- Strings
- Bytes
-
Container Types
- Tuples and Lists
- Dictionaries
- Sets
-
Primitive Types
-
Python Objects
- References to Objects
-
Chapter 2. Operators
- Arithmetic
-
Assignment
- Packing operators
- Comparison
-
Logical
- What is Truthy?
- Short-Circuits
- Logical Assignments
- Membership
- Bitwise
- Identity
-
Chapter 3. Lexical Structure
- Line Structure
- Comments
- Explicit and Implicit Line Joining
- Indentation
-
Chapter 4. Control Flow
-
if
,elif
, andelse
-
while
-
break
-
continue
-
-
for
- What is an Iterable?
-
for/else
andbreak
-
Exception Handling
-
raise from
-
else
andfinally
-
-
match
- type checking
- guards
- Or Patterns
-
as
-
-
Chapter 5. Functions
-
Function Signatures
- Explicitly positional/key-value
-
Default Values
- Mutable Types as Default Values
-
Scope
- Nested Scopes
-
nonlocal
andglobal
- Closures
- Anonymous Functions
- Decorators
-
Function Signatures
-
Chapter 6. Classes
- data types as classes.
-
__dunder__
methods-
The
__init__
method
-
The
- Attributes
- Class Attributes
- A Functional Approach
-
@staticmethod
-
@classmethod
-
Chapter 0: System Setup
-
Part II. A Deeper Dive
-
Chapter 7. Expressions, Comprehensions, and Generators
- Generator Expressions
-
Generator Functions
-
yield from
-
- List Comprehensions
- Dictionary Comprehensions
- Expressions and the Walrus Operator
-
Chapter 8. Python’s Built-in Functions
- Type Conversions
- Mathematical Functions
-
all()
andany()
-
dir()
-
enumerate()
-
eval()
andexec()
-
map()
-
filter()
-
input()
andprint()
-
open()
-
range()
-
sorted()
-
reversed()
-
zip()
-
Chapter 9. The Python Data Model
-
Object Creation Using
__new__
and__init__
- Singletons
- Rich Comparisons
-
Operator Overloading
- String Representations
- Emulating Containers
- Emulating Functions
- Using Slots
- Customizing Attribute Access
-
Iterators
- Lazy Evaluation
- Context Managers
- Descriptors
-
Object Creation Using
-
Chapter 10. Concepts in Object-Oriented Programming
-
Inheritance
-
Calling the Super Class using
super()
- Multiple Inheritance and Method Resolution Order
-
Calling the Super Class using
- Encapsulation
- Polymorphism
-
Inheritance
- Chapter 11. Metaclasses
-
Chapter 12. The Data Types, Revisited.
- Numbers
-
Integers
- Bits and Bytes
-
Floats
- Float Methods
- Hex Values
- Complex Numbers
-
Strings
- Split and Join
- Search and Replace
- Paddings
- Formatting
- Translating
- Partitioning
- Prefixes and Suffixes
- Boolean Checks
- Case Methods
- Encodings
-
Bytes
- Decoding
- Hex Values
- Tuples
-
Lists
- Counting and Indexing
- Copying
- Mutations
- Orderings
-
Dictionaries
- Iter Methods
- Getter/Setter Methods
- Mutations
- Creating new Dictionaries
-
Sets
- Mutations
- Set Theory
- Boolean Checks
- Copying
-
Chapter 13. Type Hints
- Incorporating Type Hints
- Union types
-
Optional
-
type|None
-
- Literal
- Final
- Type aliases
-
NewType
- Generic Types
-
Protocols
- Runtime type checking
- TypedDict
-
Chapter 14. Modules, Packages, and Namespaces
-
Modules
- Module Attributes
-
if __name__ == "__main__":
-
Packages
- Imports within packages
- Installation
-
Modules
-
Chapter 7. Expressions, Comprehensions, and Generators
-
Part III. The Python Standard Library
- Chapter 15. Virtual Environments
- Chapter 16. Copy
-
Chapter 17. Itertools
- Chaining Iterables
- Filtering Iterables
- Cycling Through Iterables
- Creating Groups
- Slicing Iterables
- Zip Longest
-
Chapter 18. Functools
- Partials
-
Reduce
- Pipes
- Caching
- Dispatching
-
Chapter 19. Enums, NamedTuples, and Dataclasses
- Enums
- NamedTuples
- Dataclasses
-
Chapter 20. Multithreading and Multiprocessing
-
Multithreading
- Thread Locks
-
Multiprocessing
- Process and Pool
- Process Locks
- Pipes and Queues
-
concurrent.futures
-
Multithreading
-
Chapter 21. Asyncio
- Coroutines
-
Tasks and Task Groups
-
ExceptionGroup
and Exception unpacking
-
-
Part VI. The Underbelly of the Snake
-
Chapter 22. Debugging
- pdb
- Other Debuggers
-
Chapter 23. Profiling
-
cProfile
-
flameprof
-
snakeviz
-
-
memory_profiler
-
cProfile
-
Chapter 24. C extensions
-
Hello World
-
hello_world.c
-
setup.py
-
-
Passing data in and out of Python
- Memory Management
-
Parsing Arguments
- Parsing Tuple Arguments
- Parsing Keyword Arguments
- Creating PyObjects
- Importing Modules
- Defining New Types
-
Stack
type - Debugging C extensions
-
Hello World
-
Chapter 22. Debugging
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 earnedover $14 millionwriting, 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