20
Python 2 in Python 3!
(programming.dev)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
Alright, here are my solutions :)
Not the most technically interesting, but a fun Easter egg!
Decorators are another way of calling a function, so can be abused to solve this task. You need to decorate a class rather than a function though, since a function definition requires parentheses!
There might be some other Dunder methods you can use to do this, although it's sort of difficult since most (e.g.
__add__
) only describe behaviour on the instance of the class.Writing number 3 made me realise I just needed to find a class that already had an instance and change that. I'm sure there are many other cases of this, but here's one!
Very interesting solutions. I was in the direction of using dunder methods but could not figure out how. Haven't heard of the
__class_getitem__
. The second solution is especially inspiring.