Python: is 'int' a type or a function?
<p>I did this in Python 3.4:</p>

<pre><code>&gt;&gt;&gt; type(int)
&lt;class 'type'&gt;
&gt;&gt;&gt; int(0)
0
</code></pre>

<p>Now I am wondering what int actually is. Is it a type, or is it a function? Is it both? If it is both, is it also true that all types can be called like functions?</p>

<p><code>int</code> is a built-in class/type:</p>

<pre><code>&gt;&gt;&gt; isinstance(int, type)
True
</code></pre>

<hr>

<p>When you invoke <code>int('123')</code>, Python finds out that <code>int</code> itself is nota function, but then attempts to call <code>int.__call__('123')</code>; this itself resolves to  <code>type.__dict__['__call__']</code>; this is called with <code>(int, '123')</code> as arguments. The default <code>__call__</code> implementation of <code>type</code> tries to construct a new object of the type given as the first argument (here <code>int</code>, by calling the <code>__new__</code> method on that type class; thus the behaviour of <code>int('123')</code> indirectly comes from <code>int.__new__(int, '123')</code>, which constructs a new <code>int</code> instance that has the value of the given string parsed as an integer.</p>

python