/Python-for-Those-Who-Cannot-Even

The Python book for developers who miss curly braces. Learn real Python while complaining about whitespace. 15 chapters of education, commiseration, and reluctant acceptance. For programmers who know better but have no choice.

Creative Commons Zero v1.0 UniversalCC0-1.0

Python for Those Who Cannot Even

A Reluctant Guide to a Language That Uses Whitespace as Syntax

About This Book

Look, we're all here for different reasons. Maybe your boss told you to learn Python. Maybe you lost a bet. Maybe you just hate yourself a little bit. Whatever brought you here, welcome to the support group.

This book teaches Python to people who:

  • Already know how to program in a real language (one with curly braces)
  • Miss semicolons like old friends who moved away
  • Think significant whitespace is what happens when your spacebar gets stuck
  • Would rather be writing Ruby but the job market said "lol no"

Table of Contents

  • The Great Indentation Disaster of 1991
  • Why Guido van Rossum Hurt Us This Way
  • Setting Up Your Therapy Session (Development Environment)

Part I: The Basics Nobody Asked For

  • Everything is an Object (Even Your Disappointment)
  • Dynamic Typing: Because Who Needs Compile-Time Safety?
  • The Walrus Operator := (Yes, That's Really What It's Called)
  • If Statements: The Art of Significant Indentation
  • Loops: While You Question Your Life Choices
  • The Else Clause on Loops (Because Python)
  • F-Strings: Python's One Good Idea
  • Triple Quotes: For When You Have a Lot to Say
  • String Methods That Almost Make Sense

Part II: Data Structures (Or: How Python Stores Your Regrets)

  • Lists: Mutable Arrays That Wish They Were Ruby Arrays
  • Tuples: Immutable Lists That Nobody Asked For
  • List Comprehensions: One-Liners That Make You Feel Smart
  • Dictionaries: At Least These Are Useful
  • Sets: For When You Want Unique Disappointments
  • The Mysterious OrderedDict (Spoiler: All Dicts Are Ordered Now)

Part III: Functions and the Art of Pretending to Care

  • Default Arguments: The Mutable Default Trap
  • *args and **kwargs: When You've Given Up on Type Safety
  • Lambda Functions: Anonymous Functions Nobody Can Read
  • What Even Is a Decorator?
  • Writing Your Own Decorators (Don't)
  • Common Decorators That Actually Matter

Part IV: Object-Oriented Programming (Because Everything Has Issues)

  • The Eternal Mystery of self
  • __init__ and Other Dunder Methods
  • Why Everything Needs Double Underscores
  • Single Inheritance: At Least It's Not Multiple
  • Super() and the Method Resolution Order
  • Abstract Base Classes: Python Pretends to Have Interfaces

Part V: Advanced Topics You'll Probably Never Use

  • Yield: Not Just for Traffic
  • Generator Expressions: List Comprehensions' Lazy Cousin
  • The Iterator Protocol: Making Things Iterable
  • What's a Context Manager?
  • Writing Your Own (But Why?)
  • Common Context Managers You'll Actually Use
  • Asyncio: Making Simple Things Complicated Since 2014
  • Async/Await: JavaScript Refugees Will Feel at Home
  • When to Use Async (Spoiler: Less Often Than You Think)

Part VI: The Ecosystem (Or: pip install your-problems-away)

  • pip: Installing Packages and Breaking Things
  • Virtual Environments: Because Global Installation is Too Easy
  • Poetry, Pipenv, and Other Tools That Promise to Fix Everything
  • unittest: Java Programmers Will Feel at Home
  • pytest: The Actually Good Testing Framework
  • Mocking: Pretending Your Code Works
  • You've Learned Python (Unfortunately)
  • Career Opportunities in Suffering
  • Resources for Continued Disappointment

How to Use This Book

Each chapter includes:

  • Reluctant explanations of Python concepts
  • Bitter comparisons to better languages
  • Actual working code (despite our complaints)
  • Exercises titled "Try Not to Cry"

Prerequisites

  • Basic programming knowledge in any language with curly braces
  • A sense of humor about your poor life choices
  • A therapist on speed dial
  • Coffee (lots of it)

About the Author

The author is a programmer who was perfectly happy writing Ruby until the job market had other ideas. They now write Python professionally while secretly maintaining a Ruby shrine in their closet.

License

This book is distributed under the "Whatever, It's Python" license. Do what you want with it. We're all suffering together.