How to convert 007898989 to 7898989 in Python
<p>I am trying to convert <code>007898989</code> to <code>7898989</code> in Python using the following code:</p>

<pre><code>long(007898989)
</code></pre>

<p>However this leads to the following error:</p>

<pre><code>&gt;&gt;&gt; long(007898989)
  File "&lt;stdin&gt;", line 1
    long(007898989)
                 ^
SyntaxError: invalid token
</code></pre>

<p>How can I convert this number correctly?</p>

<p><code>007898989</code> is not a valid number in Python since numbers starting with a <code>0</code> are supposed to be octal numbers and cannot contain 8 or 9. For example <code>077</code> octal is the same as <code>63</code> decimal. In Python 2, you can write this code:</p>

<pre><code>&gt;&gt;&gt; 077
63
</code></pre>

<p>This could trigger some serious bugs if not handled carefully. Therefore, for Python 3, numbers with leading zero's are no longer allowed:</p>

<pre><code>&gt;&gt;&gt; 077
  File "&lt;stdin&gt;", line 1
    077
      ^
SyntaxError: invalid token
</code></pre>

<p>Luckily, you can easily convert a numeric string with leading 0's in Python 2 to a long integer using this syntax:</p>

<pre><code>long('007898989', base = 10)
long('007898989') # Since base defaults to 10 anyway
</code></pre>

<p>For Python 3 <code>int</code> already has unlimited precision, therefore long is not supported anymore. For Python 3, you can simply use:</p>

<pre><code>int('007898989')
</code></pre>

python