Solihull Solihull - 3 months ago 22
Python Question

Python strftime - date without leading 0?

When using Python

strftime
, is there a way to remove the first 0 of the date if it's before the 10th, ie. so
01
is
1
? Can't find a
%
thingy for that?

Thanks!

Answer

You can use left strip to remove the leading zero's

day = day.lstrip('0')

>>> day = '01'
>>> day.lstrip('0')
'1'
Comments