So imagine I want to go over a loop from 0 to 100, but skipping the odd numbers (so going \"two by two\").
for x in range(0,100):
if x%2 == 0:
print
(Applicable to Python <= 2.7.x only)
In some cases, if you don't want to allocate the memory to a list then you can simply use the xrange() function instead of the range() function. It will also produce the same results, but its implementation is a bit faster.
for x in xrange(0,100,2):
print x, #For printing in a line
>>> 0, 2, 4, ...., 98
Python 3 actually made range
behave like xrange
, which doesn't exist anymore.