How to specify argument types?
<p>I'm very much a Python newbie, but I've searched for a solution and I'm stumped. </p>

<p>I have defined a function which accepts several arguments:</p>

<pre><code>def func(arg1, arg2, arg3):
</code></pre>

<p>The first argument will be a string but the next two are always going to be integers. I need to construct the following <code>for</code> loop.</p>

<pre><code>for x in range(0, arg2 / 2):
</code></pre>

<p>The problem is that <code>arg2</code> is defaulting to type <code>float</code> and as a result I get the following:<br>
<code>TypeError: 'float' object cannot be interpreted as an integer</code></p>

<p>I have tried: </p>

<pre><code>for x in range(0, int(arg2) / 2): 
</code></pre>

<p>But the same thing happens for some reason. How can I specify that <code>arg2</code> should be taken as an integer, or how can I reinterpret it as an integer?</p>

<p>In Python 3.x:</p>

<p>When you <code>arg2 / 2</code> you will get a float. If you want an int try <code>arg2 // 2</code></p>

<p>For example <code>2 / 2 = 1.0</code> but <code>2 // 2 = 1</code> </p>

<p>But you will lose accuracy doing this, but since you want an int I'm assuming you want to round up or down anyways. </p>

<p>In python 2.x / is an int division by default; to get a float division, you had to make sure one of the number was a float.</p>

<p>Edited:
As @martineau pointed out, in both Python 2.x and 3.x if the numerator or denominator is a float, / will do float division and // will result in a float result. To get around this cast it to int or make sure it's an int... 
<code>2.0 / 2 = 1.0</code> and <code>2.0 // 2 = 1.0</code> and <code>2 / 2.0 = 1.0</code> and <code>2 // 2.0 = 1.0</code>
<code>2.5 / 2 = 1.25</code> and <code>2.0 // 2 = 1.0</code> and <code>2 / 2.5 = 0.8</code> and <code>2 // 2.5 = 0.0</code></p>

python python-3.x arguments formats