Python string function to make 10 character alphanumeric id

Viewed 38

I am working with python. I need to generate string of 10 count, where I have two known value of unknown length, so after adding these two numbers the remaining place will be filled by zero between these two known strings. For example: "abcd" + "1234" should give output abcd001234.

"xyz" + "12" should give output xyz0000012.

Please help. Thanks

1 Answers
def format_string(s, num, count = 10):
    n = count - len(s)
    return s + str(num).zfill(n)

Example:

format_string("abcd", 1234)
'abcd001234'

format_string("xy", "12")
'xy00000012'
Related