explaingit

satwikkansal/wtfpython

Analysis updated 2026-06-20

36,926PythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

A collection of Python code snippets that produce baffling, unexpected results, each with a clear explanation of why. Perfect for discovering the quirks that trip up even experienced Python developers.

Mindmap

mindmap
  root((wtfpython))
    What it is
      Surprising code snippets
      Detailed explanations
      Educational resource
    Topics covered
      String interning
      Mutable defaults
      Scoping rules
      Float behavior
    Sections
      Strain your brain
      Slippery Slopes
      Hidden treasures
      Deceptive appearances
    Use cases
      Learn Python deeply
      Interview prep
      Avoid real bugs
    Format
      GitHub markdown
      Google Colab notebook
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Discover and understand Python behaviors that cause real-world bugs

USE CASE 2

Prepare for technical interviews that test deep Python knowledge

USE CASE 3

Level up from beginner to advanced by learning language edge cases

USE CASE 4

Run surprising snippets interactively in Google Colab to see the behavior yourself

What is it built with?

Python

How does it compare?

satwikkansal/wtfpythonbabysor/mockingbirdhuggingface/pytorch-image-models
Stars36,92636,89736,758
LanguagePythonPythonPython
Setup difficultyeasyhardmoderate
Complexity2/54/53/5
Audiencedeveloperresearcherresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

No installation needed, read directly on GitHub. An interactive Google Colab notebook is also available to run snippets in the browser.

Open-source educational content, free to read, share, and learn from.

In plain English

wtfpython is a collection of surprising, counter-intuitive, or confusing Python code snippets, each followed by a detailed explanation of what is actually happening. The project's tagline is "What the f*ck Python", capturing the reaction developers often have when they run a piece of valid Python code and get output that seems completely wrong. The goal is to explore and explain the underlying mechanics that cause these surprising behaviors. Each example follows a consistent structure: a short code snippet is shown, the output is displayed (which is unexpected), and then a detailed explanation digs into the Python language rules, CPython implementation details, or subtle design decisions that produce that output. Topics covered include Python's string interning (when two strings that look identical are or are not the same object in memory), the behavior of mutable default function arguments, how the "is" operator differs from equality checks, scoping rules in closures, how floating-point numbers behave, the timing of variable evaluation in loops, and many other nuanced behaviors. The examples are organized into sections: "Strain your brain" (the truly surprising ones), "Slippery Slopes" (common pitfalls that lead to real bugs), "Hidden treasures" (obscure but valid Python features), and "Appearances are deceptive" (code that looks different than it behaves). An interactive version is available as a Google Colab notebook. You would use this repository if you are learning Python and want to understand edge cases more deeply, if you are preparing for interviews that probe Python knowledge, or if you simply enjoy learning a language through its quirks. It is a documentation and educational resource, not runnable application code, and the language throughout is Python.

Copy-paste prompts

Prompt 1
Explain why Python's mutable default arguments cause unexpected behavior, can you show me an example and a fix?
Prompt 2
What's the difference between == and 'is' in Python, and when does it cause bugs? Use examples from wtfpython.
Prompt 3
I keep hearing about Python string interning, what is it and when does it matter for my code?
Prompt 4
What are the most common Python pitfalls for developers coming from JavaScript or other languages?

Frequently asked questions

What is wtfpython?

A collection of Python code snippets that produce baffling, unexpected results, each with a clear explanation of why. Perfect for discovering the quirks that trip up even experienced Python developers.

What language is wtfpython written in?

Mainly Python. The stack also includes Python.

What license does wtfpython use?

Open-source educational content, free to read, share, and learn from.

How hard is wtfpython to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is wtfpython for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub satwikkansal on gitmyhub

Verify against the repo before relying on details.