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>You're casting the input to an integer with <code>int</code>, so you're removing trailing zeroes. Integers don't preserve their trailing zeroes, so when converted it becomes a single digit:</p>

<pre><code>int("002")
# 2
</code></pre>

<p>You should remove the first int call, save it as a string until you split it up in the list comprehension:</p>

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

python