For Loops w/ Numeric Sequences
Last updated
Last updated
With studying Computer Science, we can use a lot of integers. By using range()
function along with a for loop
, we can start to analyze integer based sequences.
range()
functionThe range()
function can take 3 different arguments and it must have atleast 1 argument.
The range()
function is a function that generates an iterable sequence of integers in an arithmetic progression.
Different Behaviours of: range()
range(n)
returns a sequence of [0,n)
range(a,b)
returns a sequence of [a,b)
; if a == b, it is an empty sequence
range(start, end, interval_value)
returns a sequence of [start,end)
, but the sequence will approach the end value by adding each step with the interval value. if the interval_value
is not specified, it is assumed to be 1.
NOTE: range()
never includes the last/ending value.
range()
Since range()
returns an iterable sequence, we can look through each individual values in it with a for loop
.