What is xrange in Python
The xrange()
function in Python is used to generate a sequence of numbers, similar to the range()
function. However, xrange()
is used only in Python 2.x, whereas range()
is used in Python 3.x.
Syntax: xrange(start, end, step)
- start: Optional. Specify the starting position of the sequence of numbers.
- end: Specify the ending position of the sequence of numbers
- step: Optional. The difference between each number in the sequence.
It returns a xrange() object.
>>> x = xrange(5) >>> print(type(x)) <type 'xrange'> >>> >>> for n in x: ... print(n) ... 0 1 2 3 4 >>>
Subscribe
Login
Please login to comment
0 Discussion