For loops loop in a specified range.

Syntax-

for var_name in range (start_num, end_num):

body of loop

var_name is equal to start_num, then start_num + 1 on the next loop and so on until we reach end_num (don’t run end_num)

Example-

def sun():

image = SimpleImage(’apple_tree.jpg’)

width = image.width

height = image.height

for y in range (0, height):

for x in range (0, width):

pixel = image.get_pixel (x, 0)

pixel.red = 255

pixel.green = 165

pixel.blue = 0

return image