You can also use range;

>>> for i in range(0, 5):
...     print(i + 1)
... 
1
2
3
4
5
>>>

or in reverse:

>>> for i in range(5, 0, -1):
...     print(i)
... 
5
4
3
2
1
>>> 

On Saturday, 14 November 2020 at 21:26:04 UTC+2 vicker...@gmail.com wrote:

> Python has the enumerate function for these situations.
>
> for i, item in enumerate(items):
>      #your print statement here
>
> 'i' will give you the index of the list/iterable, and item will give you 
> the item.
>
> On Sat, 14 Nov 2020 at 11:57, paidjoo indo <leoa...@gmail.com> wrote:
>
>> Hello I'm newbie in python, I'm learning looping in python, how to print 
>> like in bellow;
>> Input:5
>> 12345 
>> 2.      4
>> 3       3
>> 4       2
>> 54321
>>  Thanks guys
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAO%3D2VJmeOF5SyMZUFox_hHivTr%3DE%3Dnekj_n7FLOYjGOkPHQrbA%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAO%3D2VJmeOF5SyMZUFox_hHivTr%3DE%3Dnekj_n7FLOYjGOkPHQrbA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/281ee4c1-23bb-4eb2-a8d3-a9bc1a13e078n%40googlegroups.com.

Reply via email to