explaingit

leisurelicht/wtfpython-cn

12,732Jupyter NotebookAudience · developerComplexity · 1/5Setup · easy

TLDR

A Chinese translation of the wtfpython project: a collection of surprising Python code examples with explanations of the real behavior behind each confusing result. A learning resource, not a library, nothing to install.

Mindmap

mindmap
  root((repo))
    What it is
      Chinese translation
      wtfpython project
      Learning resource
    Content sections
      Strain your brain
      Slippery Slopes
      Hidden treasures
      Visual tricks
    Topics covered
      is vs equals
      Mutable defaults
      Closure variables
      Loop modification
    How to use it
      Read the README
      Run Jupyter notebook
      No install needed
    Audience
      Chinese Python devs
      Beginners and veterans
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

Things people build with this

USE CASE 1

Read through counterintuitive Python examples to understand how the language actually behaves under the hood.

USE CASE 2

Run the Jupyter notebook version interactively in a browser to test surprising code snippets without installing anything.

USE CASE 3

Study Python edge cases and gotchas as preparation for a technical interview or code review.

Tech stack

PythonJupyter Notebook

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository is a Chinese translation of the English project called wtfpython, which collects surprising and counterintuitive Python code snippets. Each entry shows a short piece of Python code whose output looks wrong or confusing at first glance, then explains the actual Python behavior behind it. The goal is to help programmers understand how Python really works under the hood, not just how it appears to work on the surface. The examples are grouped into several sections. One section is called "Strain your brain" and covers things like unexpected string behavior, the difference between the is and == operators, and Python's rules for how variables are shared across closures. Another section, "Slippery Slopes", covers common mistakes like modifying a list or dictionary while looping over it, or using a mutable object as a default function argument. A section called "Hidden treasures" shows lesser-known Python features that most programmers have never encountered. There is also a section on visual tricks, where code looks like it should work one way but does something different because of invisible characters or unusual Unicode. The README itself is in Chinese, so the primary audience is Chinese-speaking Python developers. The original English version of this project, by Satwikkansal, is linked at the top. A Jupyter notebook version is also available via a web link, letting you run the code examples interactively in a browser without installing anything. This is a learning resource and a reference, not a library or tool you install. Reading through it is useful both for beginners who want to understand Python's quirks and for experienced developers who want to double-check their assumptions about how certain edge cases behave. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Explain why using a mutable default argument like a list in a Python function definition causes unexpected behavior across multiple calls.
Prompt 2
Show me Python examples where the 'is' operator gives a different result than '==' and walk me through why each one behaves that way.
Prompt 3
Reproduce the Python closure gotcha where a loop variable is captured by reference inside a lambda, and show the correct fix.
Prompt 4
Demonstrate why modifying a dictionary or list while iterating over it in Python can skip items, and show the safe pattern to use instead.
Prompt 5
Walk me through the wtfpython example about Python string interning, why do two strings with the same value sometimes share the same object and sometimes not?
Open on GitHub → Explain another repo

← leisurelicht on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.