>>> n = 5 #length of list
>>> list = [None] * n #populate list, length n with n entries"None"
>>> print(list)
[None, None, None, None, None]
>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[None, None, None, None, 1]
>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[None, None, None, 1, 1]
>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[None, None, 1, 1, 1]
或者,列表中沒有任何內容可以開始:>>> n = 5 #length of list
>>> list = [] # create list
>>> print(list)
[]
>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[1]
在附加的4迭代中:>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[1,1,1,1]
5 和所有後續:>>> list.append(1) #append 1 to right side of list
>>> list = list[-n:] #redefine list as the last n elements of list
>>> print(list)
[1,1,1,1,1]