Pad python floats
‘%03.1f’ works (1 could be any number, or empty string): >>> “%06.2f”%3.3 ‘003.30’ >>> “%04.f”%3.2 ‘0003’ Note that the field width includes the decimal and fractional digits.
‘%03.1f’ works (1 could be any number, or empty string): >>> “%06.2f”%3.3 ‘003.30’ >>> “%04.f”%3.2 ‘0003’ Note that the field width includes the decimal and fractional digits.
NumPy 1.7.0 (when numpy.pad was added) is pretty old now (it was released in 2013) so even though the question asked for a way without using that function I thought it could be useful to know how that could be achieved using numpy.pad. It’s actually pretty simple: >>> import numpy as np >>> a = … Read more
You can do this with str.ljust(width[, fillchar]): Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). The original string is returned if width is less than len(s). >>> ‘hi’.ljust(10) ‘hi ‘