tabStr += '%-15s = %6.*f
' % (id, i, val)
where i
is the number of decimal places.
BTW, in the recent Python where .format()
has superseded %
, you could use
"{0:<15} = {2:6.{1}f}".format(id, i, val)
for the same task.
Or, with field names for clarity:
"{id:<15} = {val:6.{i}f}".format(id=id, i=i, val=val)
If you are using Python 3.6+, you could simply use f-strings:
f"{id:<15} = {val:6.{i}f}"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…