Op 11-04-15 om 19:41 schreef Jim Mooney:
Why does the first range convert to a list, but not the second?

p = list(range(1,20)), (range(40,59))
p
([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
  range(40, 59))



I'm not sure I understand correctly. This is what the top of help(range) says:

<
Help on class range in module builtins:

class range(object)
 |  range(stop) -> range object
 |  range(start, stop[, step]) -> range object
 |
 |  Return a virtual sequence of numbers from start to stop by step.
>

So range() returns a range object. In your example you convert the first one to a list with list(), but not the second, so it prints the range object.

>>> range(2)
range(0, 2)
>>> list(range(2))
[0, 1]

Timo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to