Difference between revisions of "Range"
Jump to navigation
Jump to search
(Created page with "<c>range</c> Return a list containing a series of numbers within a range. from (number, default 0): first number to include in the list to (number, default 0): point at which...") |
(Added examples) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | <c>range</c> | + | <c>range(from, to, step)</c> returns a list containing a series of numbers within a range. |
− | |||
− | |||
− | |||
− | + | * <c>from</c> (number, default 0): first number to include in the list | |
+ | * <c>to</c> (number, default 0): point at which to stop adding numbers to the list | ||
+ | * <c>step</c> (number, optional): amount to add to the previous number on each step; defaults to 1 if to > from, or -1 if to < from | ||
− | <ms>range(50, 5, -10) | + | == Examples == |
+ | |||
+ | <ms> | ||
+ | range(1, 5) // returns [1, 2, 3, 4, 5] | ||
+ | |||
+ | range(5) // returns [5, 4, 3, 2, 1, 0] | ||
+ | range(5, 1) // returns [5, 4, 3, 2, 1] | ||
+ | |||
+ | range(1, 10, 2) // returns [1, 3, 5, 7, 9] | ||
+ | |||
+ | range(50, 5, -10) // returns [50, 40, 30, 20, 10] | ||
+ | </ms> | ||
[[Category:Intrinsic Functions]] | [[Category:Intrinsic Functions]] |
Latest revision as of 23:38, 5 December 2021
range(from, to, step)
returns a list containing a series of numbers within a range.
from
(number, default 0): first number to include in the listto
(number, default 0): point at which to stop adding numbers to the liststep
(number, optional): amount to add to the previous number on each step; defaults to 1 if to > from, or -1 if to < from
Examples
range(1, 5) // returns [1, 2, 3, 4, 5]
range(5) // returns [5, 4, 3, 2, 1, 0]
range(5, 1) // returns [5, 4, 3, 2, 1]
range(1, 10, 2) // returns [1, 3, 5, 7, 9]
range(50, 5, -10) // returns [50, 40, 30, 20, 10]