2

I have a tuple of a range of numbers to indicate dates. I would like to zeropad the numbers so that the tuple if possible.

current results ( 1,2,3,4,5....10,11,12, etc) wanted results (01,02,03,... 10,11,12, etc)

1 Answers1

1

You can use zfill.

>>> tuple(str(x).zfill(2) for x in range(1,31))
('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30')
abc
  • 11,579
  • 2
  • 26
  • 51