-3

I wonder what is the difference between the range() and the xrange() functions in python. I have seen them used equally many times.

1

1 Answer 1

0

In Python 2.X range() creates a list. You can assign it to a variable. But xrange() creates an object that is used for iteration. range() consumes memory for each of its elements while xrange() doesn't have elements. I've read that xrange is better to conserve memory.

They discuss this more on What is the difference between range and xrange functions in Python 2.X?

Sign up to request clarification or add additional context in comments.

1 Comment

You shouldn't answer questions that have been answered repeatedly. Please see How to Answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.