Initialize variable depending on another variables type
<p>In Python 2.7 I want to intialize a variables type depending on another variable.</p>

<p>For example I want to do something like:</p>

<pre><code>var_1 = type(var_2)
</code></pre>

<p>Is there a simple/fast way to do that?</p>

<pre><code>a = 1              # a is an int
a_type = type(a)   # a_type now contains the int-type
b = '1'            # '1' is a string
c = a_type(b)      # c is now an int with the value 1
</code></pre>

<p>So you can get the type of a variable using <code>type()</code>. You can then store this type in a variable and you can then use that variable just like you would use <code>int(b)</code>, <code>str(b)</code>, <code>float(b)</code> etc. </p>

python python-2.7