[Tutor] Range command

Mats Wichmann mats at wichmann.us
Wed Jun 26 19:29:08 EDT 2019


On 6/26/19 5:07 PM, Brick Howse via Tutor wrote:
> Hello all, 
> 
> New to programming and I noticed the range command did not function like it does in the tutorial. 
> For example,
> I type 
>>>>> range(5, 10)
> And the output is 
> range(5, 10)
> 
> In section 4.3
> It shows it should display 
>>>>> range(5, 10)
> 5, 6, 7, 8, 9
> 
> I'm using windows 10 
> Python 3.7.3
> 
> Any suggestions is greatly appreciated.

Things change.  You have a Python2-oriented tutorial.  Neither version
is wrong.  In Python2, range returns a list.  In Python3, range returns
a range object, which you can iterate over.  So for a typical use, which
is to iterate over the range, the results are identical:

>>> for i in range(5,10):
...     print(i)
...
5
6
7
8
9





More information about the Tutor mailing list