How to accept 0 as a value in a list? and When I enter the numbers after a space I get an error
<p>Everytime I enter a value such as 002
the length comes out as 1 however it should come out as 3
My code is:</p>

<pre><code>list1  = int(input("Enter a number"))
list1 = [int(x) for x in str(list1)]
print (len(list1))
</code></pre>

<p>If I type in a number after a space I get an error saying:</p>

<pre><code>File "C:\\practice11.py", line 2, in &lt;module&gt;
  list1 = [int(x) for x in text]
File "C:\\practice11.py", line 2, in &lt;listcomp&gt;
  list1 = [int(x) for x in text]
</code></pre>

<p>ValueError: invalid literal for int() with base 10: ' '</p>

<p>If you do:</p>

<pre><code>s = "002"
i = int(s)
print(i)
</code></pre>

<p>outputs</p>

<pre><code>2
</code></pre>

<p>because leading 0 are dropped during the casting to int. As a matter of fact,</p>

<pre><code>i = 002
</code></pre>

<p>is illegal and yields</p>

<pre><code>SyntaxError: invalid token
</code></pre>

<p>So you can't go <code>string &gt; int &gt; string</code> to count the characters, why not doing this instead:</p>

<pre><code>s = input("Enter a number")
print (len(s))
</code></pre>

python