Python - Using range with List comprehensions

Introduction

A range is a built-in function that generates successive integers.

It requires a surrounding list to display all its values in 3.X only.

Python 2.X makes a physical list all at once:

Demo

print( list(range(4)) )                           # 0..3 (list() required in 3.X) 
print( list(range(-6, 7, 2)) )                    # -6 to +6 by 2 (need list() in 3.X) 
print( [[x ** 2, x ** 3] for x in range(4)] )     # Multiple values, "if" filters 
print( [[x, x / 2, x * 2] for x in range(-6, 7, 2) if x > 0] )

Result

Related Topic