What is a <class 'range'>
<p>Python3:</p>

<pre><code>string = range(10)
print("{}".format(type(string)))
</code></pre>

<p>The output: </p>

<pre><code>class 'range'
</code></pre>

<p>I am just curious about this class 'range'.
Could anyone explain?</p>

<p>But in Python2:</p>

<p>The output: </p>

<pre><code>class 'list'
</code></pre>

<p>Well, it is self explanatory</p>

<p>In Python 2 <code>range(val)</code> produces an instance of a list, it <a href="https://docs.python.org/2/library/functions.html#range" rel="nofollow">simply a function</a>. Thereby <code>type(range(10))</code> will return <code>class 'list'</code>.</p>

<p>In Python <code>3</code>, <a href="https://docs.python.org/3/library/stdtypes.html#range" rel="nofollow"><code>range</code></a> is equivalent to <a href="https://docs.python.org/2/library/stdtypes.html#typesseq-xrange" rel="nofollow"><code>xrange</code></a> in Python 2 and it returns an instance of a new class named <code>range</code>. For more changes/differences between Python 2/3 see <a href="https://www.python.org/dev/peps/pep-3100/#built-in-namespace" rel="nofollow"><code>PEP 3100</code></a>.</p>

python python-2.7 python-3.x range