Teaching the "range" function in Python 3
Rick Johnson
rantingrickjohnson at gmail.com
Sun Jul 2 11:39:28 EDT 2017
On Saturday, July 1, 2017 at 12:48:39 AM UTC-5, Christian Gollwitzer wrote:
> Am 30.06.17 um 04:33 schrieb Rick Johnson:
> > And to further drive home the point, you can manually
> > insert a list literal to prove this:
> >
> > >>> range(10)
> > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> > >>> for value in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
> > ... print(value)
> > ...
> > 0
> > 1
>
> Now you have exactly missed the point that the OP was
> asking about. In Python 2, yes, this works and it is the
> way he has teached it to his students. Howver, in Python 3:
Nah, I didn't miss the point, i just forgot to pass in a
version number to my virtual python "fetch_answer" function --
which defaults to Python2.x
def fetch_answer(question, pyver=2):
return database[pyver].get(question, "Urmm???")
> >>> range(10)
> range(0, 10)
>
> This is not helpful to understand what range does [in
> Python>=3.0], and this is the original question.
Yeah, and thanks for underscoring the obvious. ;-)
PS: Okay! Okay! So I forgot to call list on the range! So
sue me!!! ;-)
More information about the Python-list
mailing list