what exactly is a range object? i understand we must create a list with the range but what is a range object? | Sololearn: Learn to code for FREE!

+3

what exactly is a range object? i understand we must create a list with the range but what is a range object?

6/27/2016 4:56:03 AM

Yung stevie

2 Answers

New Answer

+5

Objects of type range are created using the range() function. They don’t support slicing, concatenation or repetition, and using in, not in, min() or max() on them is inefficient. This is a versatile function to create iterables yielding arithmetic progressions. It is most often used in for loops. The arguments must be integers. If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. The full form returns an iterable of integers [start, start + step, start + 2 * step, ...]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. step must not be zero (or else ValueError is raised). Example: >>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(1, 11)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> list(range(0, 30, 5)) [0, 5, 10, 15, 20, 25] >>> list(range(0, 10, 3)) [0, 3, 6, 9] >>> list(range(0, -10, -1)) [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] >>> list(range(0)) [] >>> list(range(1, 0)) []

0

I too want to know