0

For any k-digit integer i, the goal is to produce an m-digit string where the first n digits, where n=m-k are zeros, say. Using python would be helpful.

For example, given m=5 and i=324, how to produce "00324"?

EDIT: The zfill function pads the integer with zeros. Is there any more general function that pads the integer with an arbitrary integer/character?

cerebrou
  • 4,623
  • 13
  • 43
  • 69

1 Answers1

2

You can use zfill

i = 324
m = 5
s = str(i).zfill(m)
# '00324'
Nuageux
  • 1,652
  • 1
  • 16
  • 25