From the course: Python Quick Start

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Using a for loop

Using a for loop

Iteration is the process of repeatedly performing a set of instructions. A for loop is a structure that helps you achieve iteration. There are different ways you could use a for loop. One way is to use a for loop to iterate over a range of numbers. You can specify a range of numbers by calling the range function. Range is a built-in function in Python that takes in the following inputs in the following order, an optional starting number, a required ending number, and an optional step size. When a starting number is not provided, range defaults to starting with 0. When a step size is not provided, range defaults to using a step size of 1. The ending number must be provided and range excludes this ending number. For example, if you want to print out each number between 0 and 3 inclusive of 0 and 3, you would do this. for i in range (4), print(i). And I'll go ahead and run this. Note that I called the range function and provided four as the input because range excludes the ending number.…

Contents