Skip to content

Entries published on October 13, 2015

1 entry published on this date. See also: all entries published in October 2015, full archive.

Wat’s up, doc?

In much the same vein as Gary Bernhardt’s wonderful talk about JavaScript, there’s a collection of Python “wat” moments which goes around every so often. There’s also an associated quiz linked from that page (which I won’t spoil; you can read through it yourself and then check your answers). Every language has some unintuitive — or at least seemingly-unintuitive — bits, and Python is no exception. But if you’re working in Python, understanding why (or, perhaps more appropriately, wy) these snippets of code behave the way they do is interesting and potentially useful (OK, probably not useful, but at least it’s interesting). So let’s take a look at them and see what’s really going on.

Converting to a string and back”

The given example is:

>>> bool(str(False))
True

This one’s pretty straightforward: str(False) is "False", and bool("False") is True, because any …

Entry published October 13, 2015. Read full entry.