Python xrange () vs range () explained with examples
xrange () function always provides the next element on demand. It means that only one item exists in memory at a time. Hence, it consumes less memory. What to prefer xrange or range? It’s a tradeoff between an instant result or a segmented output. With xrange, we get a speedier response; also, it’s consumption of memory is lower.