Understanding variable types, names and assignment
<p>In Python, if you want to define a  variable, you don't have to specify the type of it, unlike other languages such as C and Java.</p>

<p>So how can the Python interpreter distinguish between variables and give it the required space in memory like <code>int</code> or <code>float</code>?</p>

<p>In Python all values are objects with built-in type info. Variables are references to these values. So their type is 'dynamic', just equal to the type of what they happen to refer to (point to) at a particular moment.</p>

<p>Whenever memory is allocated for the contents of a variable, a value is available. Since it has a type, the amount of memory needed is known.</p>

<p>The references (variables) themselves always occupy the same amount of memory, no matter what they point to, since they just contain a conceptual address.</p>

<p>This indeed means that in</p>

<pre><code>def f (x):
    print (x)
</code></pre>

<p>x doesn't have a type, since it doesn't have a particular value yet.
The upside is that this is very flexible.
The downside is that the compiler has only limited means to discover errors.
For this reason Python was recently enriched with <a href="http://stackoverflow.com/questions/32557920/what-are-type-hints-in-python-3-5">type hints</a>.
Tools like <a href="http://mypy-lang.org/" rel="nofollow">mypy</a> allow static typechecking, even though the interpreter doesn't need it.
But the programmer sometimes does, especially at module boundaries (API's) when she's working in a team.</p>

python