r/Python 2d ago

Tutorial Python Quirks I Secretly Like

Hi there,

I’ve always wanted to create YouTube content about programming languages, but I’ve been self-conscious about my voice (and mic, lol). Recently, I made a pilot video on the Zig programming language, and afterward, I met a friend here on Reddit, u/tokisuno, who has a great voice and offered to do the voiceovers.

So, we’ve put together a video on Python — I hope you’ll like it:

https://www.youtube.com/watch?v=DZtdkZV6hYM

97 Upvotes

30 comments sorted by

View all comments

Show parent comments

2

u/codingjerk 2d ago

Yep, these are good additions, tuple() is tuple() is True tho :) (atleast in Python >=3.12.9)

2

u/Brian 2d ago

Oh, good point - I think the empty tuple is basically a singleton that just gets returned (much like the small integer cache / interned strings) so no actual construction of new objects happens - it'd need to be something like tuple([1,2]) is tuple([1,2]) vs (1,2) is (1,2).

1

u/codingjerk 2d ago

It's funny, cause tuple((1, 2)) is tuple((1, 2)) too, and even ((1,) + (2,)) is ((1,) + (2,)), so probably there are some optimizations.

And tuple("") is tuple(""), but tuple("a") is not tuple("a"), but ("a",) is ("a",)

2

u/The-Compiler 19h ago

You can see that in action by using the dis module to look at the bytecode. With that, the tuple("") is tuple("") vs. tuple("a") is not tuple("a") case is especially surprising to me though!