In Python, how do I specify a format when converting int to string?
More precisely, I want my format to add leading zeros to have a string with constant length. For
With python3 format and the new 3.6 f"" notation:
>>> i = 5 >>> "{:4n}".format(i) ' 5' >>> "{:04n}".format(i) '0005' >>> f"{i:4n}" ' 5' >>> f"{i:04n}" '0005'