How would you add zeros to the beginning of an Integer, such that there are 4 total digits in the number?
Without using zfill or format or any other obscure functions.
example:
turn 15 into 0015
or 234 into 0234
4 comments · 75% upvoted · other discussions
zfill or format are not obscure at all.
A python integer cannot have leading zeros. It's simply not possible. zfill and format work with strings. You can also use f-strings to add zeros to a string:
That said this sounds like an XY problem. We could help a lot more if you told us what problem you are trying to solve, not just how you are trying to solve it. What's the big picture here? http://xyproblem.info