How to pad a string with leading zeros in Python 3
<p>I'm trying to make <code>length = 001</code> in Python 3 but whenever I try to print it out it truncates the value without the leading zeros (<code>length = 1</code>). How would I stop this happening without having to cast <code>length</code> to a string before printing it out?</p>

<p>Using the <code>zfill()</code> helper method to pad the string with zeros as illustrated below:</p>

<pre><code>print str(1).zfill(3);
</code></pre>

python python-3.x math rounding