Python strings have a method called zfill
that allows to pad a numeric string with zeros to the left.
In : str(190).zfill(8)
Out: '00000190'
How can I make the pad to be on the right ?
pythonstring
Python strings have a method called zfill
that allows to pad a numeric string with zeros to the left.
In : str(190).zfill(8)
Out: '00000190'
How can I make the pad to be on the right ?
Best Answer
As maybe a alternative more portable [1] and efficient [2], actually you can just use str.ljust.
[1] format is not present on old python versions. format specifier was added since Python 3.0 (see PEP 3101) and Python 2.6.
[2] reverse twice is an expensive operation.