title: how does .isdigit() work in this case?
body: <p>When I was looking for a solution for the problem "count digits in a given string containing both letters and digits" there was one with built-in function .isdigit(). Here it is:</p>
  
  <pre><code>def count_numbers1(a):
      return sum(int(x) for x in a if x.isdigit())
  </code></pre>
  
  <p>It works nicely but I cannot get how it works. I have read that the <code>.isdigit()</code> returns true if there is at least one digit in a string false otherwise. </p>
  
  <p>And one more question: how the function "takes out" the digits from the string and converts it in integers and how it skips the letters? Why <code>int(x)</code> when <code>x</code> is a letter does not produce an error? such as:</p>
  
  <pre><code>&gt;&gt;&gt; int('a')
  Traceback (most recent call last):
    File "&lt;pyshell#77&gt;", line 1, in &lt;module&gt;
       int('a')
  ValueError: invalid literal for int() with base 10: 'a'
  </code></pre>