Random Numbers, Tuples, and Lists

Lists

Lists are data structures used for storing an ordered list of items, where the position of each element is guaranteed to be fixed until the list is modified. Unlike tuples, lists can be modified after they are initialized. A pair of square brackets are used for initializing the lists.

import turtle
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']

turtle.bgcolor('black')
turtle.speed(20)

for x in range(360):
    turtle.pencolor(colors[x % 6])
    turtle.width(x / 100 + 1)
    turtle.forward(x)
    turtle.left(59)

turtle.done()

(Note: The original source of the code sample is unknown, however you can find a reference url to this example in www.geeksforgeeks.org/draw-colorful-spiral-web-using-turtle-graphics-in-python/)

How can we populate a list from the values returned by the range() function?

Using the star * notation as in:

my_list = [*range(20)]

print(my_list)

my_second_list = [*range(10,50,3)]

print(my_second_list)