Search code examples
pythonappendstring-length

Python - append zeros to beginning of numbers depending on the string length


i have python script that results in numbers, for example

1001

10001

100001

i need to append zeroes at the beginning that the length is always equal to 10

0000001001

0000010001

0000100001

i need to know how to do it in python

thanks in advance


Solution

  • i figured out an answer :

    x = 1001
    
    n = 10-len(x)
    
    zeros = '0'*n
    

    and then i can append the zeros to x value and wrap it in a str