← All open source projects

wtfpython

satwikkansal/wtfpython

wtfpython is a collection of surprising Python behavior examples.

Forks 2,668
Author satwikkansal
Language Python
License WTFPL
Synced 2026-06-27

What it is

wtfpython is a learning collection of unusual Python behavior. It became noticeable because Python looks simple, but has many edges that become clear only through small examples.

Developers can make mistakes with mutable defaults, closures, identity, object caching, and non-obvious language rules. The project is best understood not as an abstract repository, but as a concrete answer to a working problem.

In short: wtfpython collects strange, funny, and useful Python examples explaining scopes, mutability, caching, comparisons, and language details. If the task matches that shape, the project can provide a fast start without rebuilding the base infrastructure from scratch.

What is inside

The repository contains Markdown sections, short code examples, result explanations, translations, and community material.

wtfpython works as a series of small puzzles: first a surprising result, then the Python mechanics behind it. This structure matters because it explains why the project can be studied, extended, and tested on a real task.

The main technical layer is connected with Python. For a team, this hints at dependencies, environment, and skills needed for adoption or code study.

How it is used

It is used for learning, interview preparation, team error reviews, and deeper language understanding.

It is best to run each example, change one line, and check when behavior becomes expected.

A good first step is a small real scenario end to end: installation, minimal setup, one result, quality check, and notes on limits. That quickly shows where wtfpython helps immediately and where extra work is needed.

After the first run, the working configuration, input data, and expected result should be written down. That turns the first look at wtfpython into a reproducible check rather than a one-off demo impression.

Why it stands out

The strength is memorable examples that turn language surprises into knowledge.

It stands out because Python is widely used, and a popular language creates many repeated misunderstandings.

Popularity matters here not as a separate achievement, but as a signal that the problem is familiar to many people. Projects like this last when they provide a clear path from first check to regular use.

Limits

The limitation is that the collection should not encourage clever code in products; its value is understanding and prevention.

Teams can connect these examples to review and lint rules so traps do not reach working code.

Even a strong open source project is still a dependency. It needs updates, understanding, documented local settings, and a rollback path if a new version changes behavior.

That makes the project page a starting point for technical evaluation: understand the purpose, repeat a small example, and only then decide whether wtfpython belongs in regular work.

Example

Mutable default value

This example shows a classic Python trap: the list is created once, not on every call.

Language: Python
def add(value, items=[]):
    items.append(value)
    return items

print(add(1))
print(add(2))