DEV Community 👩‍💻👨‍💻

Discussion on: What is the most confusing thing to you in Python?

eanx profile image
Zack Z.

Here's a gotcha I once saw someone post involving dictionary keys:

This program:

#!/usr/bin/env python

print {0: "o hai!", False: "kthxbai", 1: "foo", True: "bar"}
print {False: "o hai!", 0: "kthxbai", True: "foo", 1: "bar"}

Yields this output:

{0: 'kthxbai', 1: 'bar'}
{False: 'kthxbai', True: 'bar'}

It never bit me in any production code, but still, I thought it was interesting enough to share.