[timukudze]
“why is it that the insert method reads from 5 to 0 and append reads
from 0 to 5”
You are calling myList.insert(0, i + 1)
so each number is inserted
before position 0, which is the beginning of the list. Always the
beginning! So you start with an empty list, and i=0:
[] insert at position 0, 0+1 = 1, gives [1]
Second time through the loop:
[1] insert at position 0, 1+1 = 2, gives [2, 1]
And so forth:
[2, 1] insert at position 0, 2+1 = 3, gives [3, 2, 1]
[3, 2, 1] insert at position 0, 3+1 = 4, gives [4, 3, 2, 1]
[4, 3, 2, 1] insert at position 0, 4+1 = 5, gives [5, 4, 3, 2, 1]
But appending always goes to the end, so you get:
[] --> [1]
[1] --> [1, 2]
[1, 2] --> [1, 2, 3]
[1, 2, 3] --> [1, 2, 3, 4]
[1, 2, 3, 4] --> [1, 2, 3, 4, 5]
An easy way to see this is to print the list each time:
myList = [] # creating an empty list
for i in range(5):
print(myList)
myList.insert(0, i + 1)
print(myList)