int() not working for floats?
<p>I recently ran into this in Python 3.5:</p>

<pre><code>&gt;&gt;&gt; flt = '3.14'
&gt;&gt;&gt; integer = '5'
&gt;&gt;&gt; float(integer)
5.0
&gt;&gt;&gt; float(flt)
3.14
&gt;&gt;&gt; int(integer)
5
&gt;&gt;&gt; int(flt)
Traceback (most recent call last):
  File "&lt;pyshell#7&gt;", line 1, in &lt;module&gt;
    int(flt)
ValueError: invalid literal for int() with base 10: '3.14'
</code></pre>

<p>Why is this? It seems like it should return <code>3</code>. Am I doing something wrong, or does this happen for a good reason?</p>

<p>It does not work because <code>flt</code> is not a string representation of an integer. You would need to convert it to <code>float</code> first then an <code>int</code>.</p>

<p>e.g.</p>

<pre><code>flt = '3.14'
f = int(float(flt))
</code></pre>

<p>output is</p>

<pre><code>3
</code></pre>

python python-3.x floating-point int