[Python] How do for-loops in Python differ from Java?

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    I’m new to Python but have a background in Java. In Java, I usually write for-loops like this:

    for (int i = 0; i < 5; i++) {
    System.out.println(i);
    }


    But in Python, I see people writing loops like this:

    for i in range(5):
    print(i)


    I want to understand the difference between the two. What exactly does range(5) mean in Python? Is there a way to write loops in Python similar to Java’s style? What’s the best way to use for-loops in Python for beginners?

    Continue reading...

Compartilhe esta Página