-1

I'm using python 3.6

when I use the range function in Python console, it didn't return an array, instead it shows the wording itself:

range(1, 5)

range(1,5)

print(range(1,5))

range(1,5)

How can I show the array?

Hyoceansun
  • 135
  • 1
  • 2
  • 10

1 Answers1

1

The range() function in Python 3 returns an iterator, something you can iterate on, so you can use it as:

for x in range(1, 5): print(x)

This iterator returns one value at a time, so it can be more memory efficient.

If you want to get a list, you can use this code:

list(range(1,3))

Szymon Lipiński
  • 27,098
  • 17
  • 75
  • 77