Python Forum

Full Version: append no working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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()
Thanks
It's not a homework problem.
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]