Search⌘ K
AI Features

Loops with Ranges

Explore how to use Python's range() function with loops to generate sequences of numbers, including even numbers, multiples, and custom arithmetic sequences. Understand how to specify start, stop, and step values, and practice writing programs that use these concepts to solve common programming problems such as printing odd numbers, multiplication tables, and checking prime numbers.

The range() function

The range() function is used to generate a sequence of values. For example, range(100) generates values 00 to 9999. If we provide two parameters to this function, like range(10,100), it generates values starting from 1010 to 9999.

It also makes it easy to specify the increment or jump value. For example, range(10,100,2) generates even values starting from 1010 and less than 100100. Note that 2 here is the stepping size.

Loop with range()

Let’s say we want to produce a program that counts from 1 ...