[Python] Why are 5 columns printing using range() in a nested loop in Python? [closed]

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    Why are 5 columns printing in the nested inner loop while using range(4)?

    The code I am running:

    for i in range(3):
    print('*', end=' ')
    for j in range(4):
    print('*', end=' ')
    print()


    Output:

    * * * * *
    * * * * *
    * * * * *


    The outer loop range(3) is printing 3 rows for 0,1,2, which is what I'm expecting. But why does the inner loop seem to not behave the same way? I'd expect it to only print 4 columns, not 5.

    Continue reading...

Compartilhe esta Página