### 5.43.40 Make a list of integers: range

The range command takes one, two or three arguments.

- For one argument, the argument must be a non-negative integer n. range will then return the list [0,1,…,n−1]
  Input:
  range(5)
  Output:
  [0,1,2,3,4]
- For two arguments, the arguments must be two numbers a and b, with a ≤ b. range will then return the list [a, a+1,…] up to, but not including, b.
  Input:
  range(4,10)
  Output:
  [4,5,6,7,8,9]
- For three arguments, the arguments must be three numbers a, b and a non-zero p. range will then return the list [a, a+p,a+2p,…] up to, but not including, b. If p > 0, then a ≤ b; if p < 0, then a ≥ b.
  Input:
  range(4,13,2)
  Output:
  [4,6,8,10,12]
  Input:
  range(10,4,-1)
  Output:
  [10,9,8,7,6,5]

The range command can be used to create a list of values f(k), where k is an integer satisfying a certain condition.

- You can list the values of an expression in a variable which goes over a range defined by range.
  Input:
  [k^2 + k for k in range(10)]
  Output:
  [0,2,6,12,20,30,42,56,72,90]
- YOu can list the values of an expression in a variable which goes over a range defined by range and which satisfies a given condition.
  Input:
  [k for k in range (4,10) if isprime(k)]
  Output:
  [5,7]
  Input:
  [k^2 + k for k in range (1,10,2) if isprime(k)]
  Output:
  [12,30,56]