Python Forum
append no working - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: append no working (/thread-17464.html)



append no working - pythonduffer - Apr-12-2019

I wrote this simple python program

L=[]

for i in range(0,5):                                        
    L.append(i)  
   
print(*L, sep = ", ")

The output is 0, 1, 2, 3, 4
Why is the output in reverse order?

Thanks


RE: append no working - Gribouillis - Apr-12-2019

It is not in reverse order. Append adds items at the end of the list. Is this a homework to print a countdown? You can obtain the reverse order by using proper arguments in the call to range()


RE: append no working - pythonduffer - Apr-12-2019

Thanks
It's not a homework problem.


RE: append no working - perfringo - Apr-12-2019

If you want to retain your current code structure then you can replace append with insert:

>>> lst = list()
>>> for i in range(0,5):
...     lst.insert(0, i)
... 
>>> lst
[4, 3, 2, 1, 0]