11 Comments

Some of these are hilarious. Thanks for sharing.

I think some deserve a little more depth. I wrote this. https://slott56.github.io/2023-08-01-python_quirks_that_arent_very_quirky.html

Expand full comment

Nice writeup. This is definitely an attempt to nerd-snipe people with some familiarity with python - after thinking about most of these more deeply, they tend to work as you would expect.

The "Identity" one is the only one that is particularly weird - there doesn't seem to be an obvious reason -5 through 256 were chosen, it's just the way it is. https://docs.python.org/3/c-api/long.html#c.PyLong_FromLong

Expand full comment

The most commonly used integers rounded to semi decimal and base 2 ranges to save on allocations from the heap

Expand full comment

Do you know if this reason is documented anywhere?

This is as good as I could find:

https://bugs.python.org/issue561244

> It may also be useful to define the small negative int (NSMALLNEGINTS) to be 5 or so instead of 1. There are several uses -2, -3, ... in the standard library.

"5 or so" makes it sound very arbitrary

Expand full comment

I was just leaving a comment saying that these all make for a short post—then I saw you had done that already! Going from "that's weird" to "that makes perfect sense" on all of these is a rite of passage!

Expand full comment

There is a large collection of Python oddities here:

https://wtfpython-interactive.vercel.app/

Expand full comment

I like the selection! They're all examples that help really understand how Python works behind the scenes! There should be a badge for when people move from "that's weird" to "that makes sense" for all of these!

Each one (almost) would make for a nice short post to show why they actually "make sense" despite looking counterintuitive…

Expand full comment

These just hurt my head and makes me wonder if my python code really works as expected!

Expand full comment

Nice writeup!

I think the "references" snippet should start with initialisation:

```

a = [[0]] * 5

```

Expand full comment

good catch, thanks!

Expand full comment

You could use capital letters Latin A, Cyrillic А and greek Alpha as variable names.

Expand full comment