For Loop with range()

1 min read ·

range() is used to generate a sequence of numbers and is commonly used with a for loop.

Basic Syntax

  • start is optional (default 0)
  • stop is excluded

Simple Example


range(start, stop)


range(start, stop, step)


Reverse Loop Using range()


Common Mistake

Note

range() always excludes the stop value.


Exercise