Limiting integer width in python
<p>I'm practicing python, I came across a situation where I wanted to limit the character width of a field but it wasn't working.(I hope I'm saying that right) I want to truncate the sum of 2 integers to 5 spaces. eg:  the sum of 88888 + 22222 has 6 characters. Is it possible to limit it to 5?</p>

<p>You can easily truncate the value of these integers. Simply convert the result into a string and then use the Python index to select the first five characters:</p>

<pre><code>&gt;&gt;&gt; str(88888 + 22222)[:5]
'11111'
</code></pre>

<p>You can also convert this value back to an integer using <code>int()</code> if necessary.</p>

python python-2.7 python-3.x