Arbitrary base for integer literals and integers in formatted strings

Hello, there, I hope you are all doing okay :smiling_face:

I have needed to display numbers in base-36 in the past, and I have always implemented a function to do so, like the one found at Python base 36 encoding - Stack Overflow

We can already do something like this

>>> f"{255:x}"
"ff"

So wouldn’t it be nice if we could do something like this?

>>> f"{255:r36}"
"73"

Or something similar that does not break the existing formatting mini-language, and for integer literals it could be something like:

>>> 255 == 36r73
True

For all bases from 2 to 36.
Is this something you would like?
I would like to help implement these features if no one is working on them :octopus:

1 Like

Thanks for the idea, but I don’t think it comes up enough to need to generalize.

NumPy does have a function for this, and my reasoning was that since we can convert from any base from 2 to 36, it’d be great to have some symmetry and be able to also convert integers to those bases :sweat_smile: but you’re right that it is not a common use case