course content

Course Content

Introduction to Python


If you don't want to iterate over elements but want to iterate over indexes, then you need to learn the range() function. range() returns a range object representing a set of numbers. This function can receive 1, 2, or 3 arguments (positive numbers). Suppose the function receives only one argument, n. In that case, it will return all the integers from 0 to n (not including n itself). For instance, range(5) will generate integers from 0 to 4.

If the function receives two arguments, n and m, it will return all the integers from n to m (not including m). For instance, range(5, 10) will return integers from 5 to 9.

If the function receives three arguments, n, m, and s, it will return integers from n to m with the step of s (not including m). For example, range(10, 30, 5) will return integers 10, 15, 20, 25.

Section 5.

Chapter 6