[Python] randint with leading zeros

Discussão em 'Python' iniciado por Stack, Agosto 12, 2025.

  1. Stack

    Stack Membro Participativo

    I want to generate numbers from 00000 to 99999.

    With

    number=randint(0,99999)


    I only generate values without leading zero's, of course, a 23 instead of a 00023. Is there a trick to generate always 5 digit-values in the sense of %05d or do I really need to play a Python-string-trick to fill the missing 0s at front in case len() < 5?

    Continue reading...

Compartilhe esta Página