How to take the nth digit of a number in python
<p>I want to take the nth digit from an N digit number in python.  For example:</p>

<pre><code>number = 9876543210
i = 4
number[i] # should return 6
</code></pre>

<p>How can I do something like that in python? Should I change it to string first and then change it to int for the calculation?</p>

<p>First treat the number like a string</p>

<pre><code>number = 9876543210
number = str(number)
</code></pre>

<p>Then to get the first digit:</p>

<pre><code>number[0]
</code></pre>

<p>The fourth digit:</p>

<pre><code>number[3]
</code></pre>

<p>EDIT:</p>

<p>This will return the digit as a character, not as a number.  To convert it back use:</p>

<pre><code>int(number[0])
</code></pre>

python int