
400 Cryptography with Open-Source Software
abbreviates
i = i+1
Ranges and lists. A range of values can be obtained with the range com-
mand. This has several variations:
range(n): Lists all values from 0 to n − 1.
range(m,n): L ists all values from m to n − 1.
range(m,n,s): Lists all values starting from m going in steps of size
s to below n.
For example:
sage: range(5)
[0, 1, 2, 3, 4]
sage: range(3,8)
[3, 4, 5, 6, 7]
sage: range(3,11,2)
[3, 5, 7, 9]
sage: range(10,1,-2)
[10, 8, 6, 4, 2]
The output of a range command is a list. Lists can be constructed by iterating
over a range, or over another list:
sage: [x^2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, ...